Re: Simulating OS semaphore behavior



On Fri, 25 Aug 2006 19:31:53 +0200, Jean-Pierre Rosen wrote:

Dmitry A. Kazakov a écrit :
That looks like a classic automatic event for multiple tasks. Make Signal
an entry:

protected body Event is
entry Wait when Signal'Count > 0 is
begin
null;
end Wait;
entry Signal when Wait'Count = 0 is
begin
null;
end Signal;
end Event;

Signal is blocked until all waiting tasks get released. There is no race
condition because fresh attempts to Wait are blocked if a signal is
pending.

However, this will cause the signaling task to wait until some task
calls wait.

Why? The Signal's barrier is open when the Wait's queue is empty.

Surely there are subtleties with the above:

1. The same task might get the same event twice if it anew queues itself to
Wait before emptying the queue.

2. There is no guaranty that all signals will be delivered to all tasks,
some might be still running while the event is pulsed.

In general it is not a reliable publisher-subscriber service, but just a
pulse event. Under system load, events might get lost or ghosted.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
.



Relevant Pages

  • Re: Simulating OS semaphore behavior
    ... entry Wait when Signal'Count> 0 is ... this will cause the signaling task to wait until some task ... The Signal's barrier is open when the Wait's queue is empty. ...
    (comp.lang.ada)
  • Re: Simulating OS semaphore behavior
    ... entry Wait when Signal'Count> 0 is ... this will cause the signaling task to wait until some task ... The Signal's barrier is open when the Wait's queue is empty. ...
    (comp.lang.ada)
  • Re: Simulating OS semaphore behavior
    ... entry Wait when Signal'Count> 0 is ... this will cause the signaling task to wait until some task calls wait. ... The classical barrier is as follows: ... protected body Barrieris ...
    (comp.lang.ada)
  • Re: Thread safe
    ... serialization and one lock for signaling. ... access to the queue: one for put and the other for get. ... And if lock contention is the problem, ...
    (comp.programming.threads)