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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,922e1768d5791765 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!news.germany.com!koehntopp.de!news.visyn.net!uucp.gnuu.de!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Simulating OS semaphore behavior Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1156518048.848919.126340@75g2000cwc.googlegroups.com> Date: Fri, 25 Aug 2006 17:09:47 +0200 Message-ID: <3zrqu2whdwk2.1fobni2jyzalh.dlg@40tude.net> NNTP-Posting-Date: 25 Aug 2006 17:09:47 CEST NNTP-Posting-Host: af44db50.newsspool4.arcor-online.net X-Trace: DXC=nQZQ9M6YE^a>jlK2>IgHGd4IUK\BH3Yb7Fd78]JaG On 25 Aug 2006 08:00:48 -0700, REH wrote: > 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. 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. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de