comp.lang.ada
 help / color / mirror / Atom feed
* Re: Simulating OS semaphore behavior
@ 2006-08-31 16:24 Anh Vo
  0 siblings, 0 replies; 14+ messages in thread
From: Anh Vo @ 2006-08-31 16:24 UTC (permalink / raw)
  To: comp.lang.ada

>>> "REH" <spamjunk@stny.rr.com> 8/25/2006 8:25 AM >>>

Dmitry A. Kazakov wrote:
> 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.
> 

Ah, just what I love: simple and elegant.  Thank you!

It is just simply beautiful, sweet and elegant solution. I had
implemented similar to Jean-Pierre's. I already changed to Dmitry's
implementation. This is another reason that Ada is in my heart.

AV 



^ permalink raw reply	[flat|nested] 14+ messages in thread
* Simulating OS semaphore behavior
@ 2006-08-25 15:00 REH
  2006-08-25 15:09 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 14+ messages in thread
From: REH @ 2006-08-25 15:00 UTC (permalink / raw)


I am porting some code from VxWorks and Ada 83 to another OS using Ada
95.  VxWorks' has a sempahore API I want to replicate with purely Ada
95 constructs, such as protected types.  The function is semFlush which
basically will release all the tasks currently blocked on the semaphore
but leave it locked, thus any new tasks that attempt to take the
semaphore will block.  I just cannot figure out a simple way to do it.

Abstractly, I want to allow an arbitrary number tasks to wait for a
particular event, and when the event occurs, wake all those tasks.
Thereafter, tasks can again block waiting for the next occurrence.
Something like:

protected type Event is
  entry Wait;
  procedure Signal;
end Event;

Implementing the above for one task seems simple enough, but how would
it been done for an arbitrary number such that the behavior is:
1. Wait's guard is initially false.
2. some tasks call Wait.
3. Signal is called.
4. Wait's guard becomes true.
5. all tasks currently queued on Wait are allowed to continue.
6. Wait's guard becomes false.

Any ideas would be greatly appreciated,

REH




^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2006-08-31 16:24 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-31 16:24 Simulating OS semaphore behavior Anh Vo
  -- strict thread matches above, loose matches on Subject: below --
2006-08-25 15:00 REH
2006-08-25 15:09 ` Dmitry A. Kazakov
2006-08-25 15:25   ` REH
2006-08-25 17:31   ` Jean-Pierre Rosen
2006-08-26  8:39     ` Dmitry A. Kazakov
2006-08-26 13:34       ` REH
2006-08-26 13:42         ` jimmaureenrogers
2006-08-27 14:00           ` Simon Wright
2006-08-26 20:18         ` Dmitry A. Kazakov
2006-08-26 20:29           ` REH
2006-08-27 17:07             ` Dmitry A. Kazakov
2006-08-27 18:02             ` Simon Wright
2006-08-27 22:28               ` REH

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