From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,6516065ab7b5a533,start X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!d27g2000yqf.googlegroups.com!not-for-mail From: Gautier write-only Newsgroups: comp.lang.ada Subject: Q: Stopping a task running a long simulation Date: Thu, 11 Mar 2010 05:08:24 -0800 (PST) Organization: http://groups.google.com Message-ID: NNTP-Posting-Host: 206.122.158.4 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1268312904 30146 127.0.0.1 (11 Mar 2010 13:08:24 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 11 Mar 2010 13:08:24 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: d27g2000yqf.googlegroups.com; posting-host=206.122.158.4; posting-account=gRqrnQkAAAAC_02ynnhqGk1VRQlve6ZG User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.0.249.89 Safari/532.5,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:10488 Date: 2010-03-11T05:08:24-08:00 List-Id: Hello, Being still a bit new to tasking, I have a question of how to terminate correctly a certain kind of task. I have a task type which is waiting for running a potentially long simulation; it is kind of a "daemon". (the rationale of using a task type is that I have several simulations that can be run in parallel, hence an array of these tasks). Now this simulation occurs within a GUI, where the user might want to stop it. Here is the task type I've defined: task type Simulation_type is entry Start; entry Run( [some parameters] ); entry Stop; end; Simulation: array(PF_version) of Simulation_type; task body Simulation_type is begin accept Start; loop select accept Stop; exit; or accept Run( [some parameters] ) do -- some quick parameter passing end Run; Compute( [some parameters] ); or delay 0.2; -- relax end select; end loop; end Simulation_type; For aborting the simulation, I have tried this (happens when the main GUI window is destroyed): for v in PF_version loop abort Daemons.Simulation(v); end loop; but (as expected if I've understood Barnes' chapter correctly), the task waits for 'Compute' to complete. At least, it is what happens with GNAT under Windows: despite the above, the GUI closes but the program somehow is still alive and CPU- busy. I have an alternative to that. 'Compute' has a generic 'Feedback' procedure for showing progress. I could with that way give a Boolean, user_abort, to 'Feedback', and 'Compute' would stop when an ad-hoc exception is raised, and return normally on its own. Meanwhile, I could call the 'Stop' entry which could be soon be activated, since Compute would stop quickly, and the daemon task would be terminated, and I could close the shop properly. Now my question: is it the right way of doing it (I'm sure it will work), or is there something more straightforward ? TIA Gautier