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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,37f13de4a5a41a8 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-04-01 04:02:44 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!fu-berlin.de!uni-berlin.de!tar-alcarin.cbb-automation.DE!not-for-mail From: Dmitry A. Kazakov Newsgroups: comp.lang.ada Subject: Re: Elegant 'abort' of sleeping task Date: Tue, 01 Apr 2003 14:02:41 +0200 Message-ID: <7mui8vsd8g4fsvj70919vapbbkrvsqgnhh@4ax.com> References: <310b040f.0303310518.76dc9bf7@posting.google.com> <3E886786.9050702@spam.com> NNTP-Posting-Host: tar-alcarin.cbb-automation.de (212.79.194.111) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: fu-berlin.de 1049198561 3788223 212.79.194.111 (16 [77047]) X-Newsreader: Forte Agent 1.8/32.548 Xref: archiver1.google.com comp.lang.ada:35856 Date: 2003-04-01T14:02:41+02:00 List-Id: On Mon, 31 Mar 2003 16:04:58 GMT, Jeffrey Carter wrote: >Simon Apperley wrote: >> >> I'm looking at the design of a piece of server code which has to >> handle calls that also pass a timeout value. The target system is >> aerospace related, and dynamically creating tasks 'on the fly' just is >> not an option. >> >> I want to be able to set up a single task to handle the timeout from >> the head of a delta-queue of timeouts, but have found a problem. If I >> have the timeout implemented as a task stuck in a 'delay' call, and a >> more immediate timeout comes in, I want to wake up the sleeping task, >> re-calculate the delta-queue and then sleep on the new, shorter, >> delay. So far the only way I can see to do this is to use abort, and >> set up the task again, which seems a bit of a brute force approach. > >It sounds as if you have something like > >loop > -- get Timeout > delay Timeout; > -- post timeout processing >end loop; > >in which case you might be able to do something like > >loop > -- get Timeout > loop > select > accept New_Timeout; > -- get Timeout; > or > delay Timeout; > -- post timeout processing > > exit; > end select; > end loop; >end loop; Just to complete the image ... Ada 95 offers also protected objects which entries can be used for timed entry calls. So a solution based on a protected object might look like: protected type Timeout_Queue is entry Get (Timeout : out Duration); -- blocks until a new timeout comes procedure Put (Timeout : Duration); -- puts a new timeout ... end Timeout_Queue; ... Queue : Timeout_Queue; ... loop select Queue.Get (Shorter_Timeout); -- get new timeout; or delay Last_Timeout; -- post timeout processing end select; end loop; BTW. For any of two alternatives, it might be better to use a schedule time (Time) instead of a timeout (Duration). If you do so, replace delay with delay until. --- Regards, Dmitry Kazakov www.dmitry-kazakov.de