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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,922e1768d5791765 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!grolier!oleane.net!oleane!hunter.axlog.fr!nobody From: Jean-Pierre Rosen Newsgroups: comp.lang.ada Subject: Re: Simulating OS semaphore behavior Date: Fri, 25 Aug 2006 19:31:53 +0200 Organization: Adalog Message-ID: References: <1156518048.848919.126340@75g2000cwc.googlegroups.com> <3zrqu2whdwk2.1fobni2jyzalh.dlg@40tude.net> NNTP-Posting-Host: mailhost.axlog.fr Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Trace: s1.news.oleane.net 1156528864 8950 195.25.228.57 (25 Aug 2006 18:01:04 GMT) X-Complaints-To: abuse@oleane.net NNTP-Posting-Date: Fri, 25 Aug 2006 18:01:04 +0000 (UTC) User-Agent: Thunderbird 1.5.0.5 (Windows/20060719) In-Reply-To: <3zrqu2whdwk2.1fobni2jyzalh.dlg@40tude.net> Xref: g2news2.google.com comp.lang.ada:6383 Date: 2006-08-25T19:31:53+02:00 List-Id: 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@adalog.fr) Visit Adalog's web site at http://www.adalog.fr