comp.lang.ada
 help / color / mirror / Atom feed
From: Dmitry A. Kazakov <mailbox@dmitry-kazakov.de>
Subject: Re: Elegant 'abort' of sleeping task
Date: Tue, 01 Apr 2003 14:02:41 +0200
Date: 2003-04-01T14:02:41+02:00	[thread overview]
Message-ID: <7mui8vsd8g4fsvj70919vapbbkrvsqgnhh@4ax.com> (raw)
In-Reply-To: 3E886786.9050702@spam.com

On Mon, 31 Mar 2003 16:04:58 GMT, Jeffrey Carter <spam@spam.com>
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



  reply	other threads:[~2003-04-01 12:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-31 13:18 Elegant 'abort' of sleeping task Simon Apperley
2003-03-31 13:28 ` Lutz Donnerhacke
2003-03-31 16:04 ` Jeffrey Carter
2003-04-01 12:02   ` Dmitry A. Kazakov [this message]
2003-03-31 16:49 ` David C. Hoos
2003-04-01 16:20 ` David C. Hoos
2003-04-01 16:26 ` Nick Roberts
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox