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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c33f8f65997c21d0 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,UTF8 Received: by 10.180.73.242 with SMTP id o18mr1079280wiv.0.1348475030394; Mon, 24 Sep 2012 01:23:50 -0700 (PDT) Path: q11ni39994397wiw.1!nntp.google.com!feeder1.cambriumusenet.nl!feeder3.cambriumusenet.nl!feed.tweaknews.nl!85.12.40.131.MISMATCH!xlned.com!feeder3.xlned.com!news.astraweb.com!border3.a.newsrouter.astraweb.com!newsfeed101.telia.com!starscream.dk.telia.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Problem with task component Date: Mon, 24 Sep 2012 09:23:49 +0100 Organization: A noiseless patient Spider Message-ID: References: <1667b8e2qt7ei$.1gg1h3hrp9amz$.dlg@40tude.net> <187uk10m6z8xj.yr1cpbgrdur$.dlg@40tude.net> Mime-Version: 1.0 Injection-Info: mx04.eternal-september.org; posting-host="5f22ba276a4b4f77c63ae2949e7306f1"; logging-data="14087"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/jFzjGZNL6iL17Uyv7oFh0o4kVuQJl7t4=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (darwin) Cancel-Lock: sha1:lq0WRjNuOq4pWo3t2jBPcJzkJUY= sha1:Js+9UVcGOsjfcQTYKecmwS/7S3Q= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Date: 2012-09-24T09:23:49+01:00 List-Id: "J-P. Rosen" writes: > Le 19/09/2012 23:48, Simon Wright a écrit : >> Using interrupts is in the next phase, for now I'm just polling by >> reading the chip's registers so I must delay & can't use terminate. A >> pain. > I don't understant what you'd want. Terminate is selected when a whole > subsystem is quiet. I you have a delay alternative, a task can be > revived, and in turn revive the whole subsystem. There is no way > terminate could be selected. The language in ARM9.3 is, now you point it out, quite opaque, especially if you approach it with wrong assumptions. The general case (common in embedded systems) is to have a task executing a loop waiting for something to happen and to need to stop the task. As Dmitry and others have pointed out, if the "something" is a network I/O, you have to arrange to cancel the I/O (eg by closing the socket) and you can then exit the task. But, if what you want is to delay, you want to write loop select delay Interval; -- do work or -- exit the loop if there's some reason to stop end select; end loop; What I wanted to do was to be able to write 'terminate' and to have the runtime realise that finalization of the object containing the task would be a good reason to take the terminate alternative[1]. [I don't know if that would work if I'd used an accept instead of a delay, which would have made the code compilable?????] Instead, the idiom needs to be loop select delay Interval; -- do work or accept Stop; exit; end select; end loop; [1] See, for example, the last three paras of John English's book ch19 sec3, http://faculty.cs.wwu.edu/reedyc/AdaResources/bookhtml/ch19.htm#19.3 This solution requires the master task to call Shutdown explicitly when it wants to terminate the task. The disadvantage with this approach is that it’s possible to forget to call Shutdown. A better solution is to add a terminate alternative to the select statement: task body Spreadsheet_Task is begin loop select accept Recalculate; Do_Recalculation; or accept Shutdown; exit; or terminate; end select; end loop; end Spreadsheet_Task; The terminate alternative must be the last one in a select statement, and it can’t contain anything except a terminate statement like the one shown above. When the master task gets to the end of the block where the spreadsheet was declared, the spreadsheet task will terminate the next time that the select statement is executed (or immediately, if the task is already waiting in the select statement). This means that the master doesn’t have to do anything special to terminate the task, but it can still call Shutdown if it wants to terminate the task before the end of the block where it was declared.