Re: Simulating OS semaphore behavior
- From: Jean-Pierre Rosen <rosen@xxxxxxxxx>
- Date: Fri, 25 Aug 2006 19:31:53 +0200
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. Generally, if there is no waiting task, Signal should do nothing. The classical barrier is as follows:
protected type Barrier is
entry Wait;
procedure Signal;
function Count return Natural;
private
Arrived : Boolean := False;
end Barrier;
protected body Barrieris
entry Wait when Arrived is
begin
if Wait'COUNT = 0 then
Arrived := False;
end if;
end Wait;
procedure Signal is
begin
if Wait'COUNT > 0 then
Arrived := True;
end if;
end Signal;
function Count return Natural is
begin
return Wait'COUNT;
end Count;
end Barrier;
--
---------------------------------------------------------
J-P. Rosen (rosen@xxxxxxxxx)
Visit Adalog's web site at http://www.adalog.fr
.
- Follow-Ups:
- Re: Simulating OS semaphore behavior
- From: Dmitry A. Kazakov
- Re: Simulating OS semaphore behavior
- References:
- Simulating OS semaphore behavior
- From: REH
- Re: Simulating OS semaphore behavior
- From: Dmitry A. Kazakov
- Simulating OS semaphore behavior
- Prev by Date: Re: protected type interrupts
- Next by Date: Re: Information On How To Use The Ada Score Compiler For Windows PC
- Previous by thread: Re: Simulating OS semaphore behavior
- Next by thread: Re: Simulating OS semaphore behavior
- Index(es):
Relevant Pages
|