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.1 required=5.0 tests=BAYES_00, PP_MIME_FAKE_ASCII_TEXT autolearn=no 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!news4.google.com!news.glorb.com!atl-c03.usenetserver.com!news.usenetserver.com!news-rtr.nyroc.rr.com!news-out.nyroc.rr.com!twister.nyroc.rr.com.POSTED!53ab2750!not-for-mail From: "REH" Newsgroups: comp.lang.ada References: <1156518048.848919.126340@75g2000cwc.googlegroups.com> <3zrqu2whdwk2.1fobni2jyzalh.dlg@40tude.net> <1gx5jdfxrewj6.19ufu2gqaakge.dlg@40tude.net> Subject: Re: Simulating OS semaphore behavior X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2869 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 Message-ID: <_5YHg.29199$8j3.16338@twister.nyroc.rr.com> Date: Sat, 26 Aug 2006 13:34:50 GMT NNTP-Posting-Host: 69.205.134.80 X-Complaints-To: abuse@rr.com X-Trace: twister.nyroc.rr.com 1156599290 69.205.134.80 (Sat, 26 Aug 2006 09:34:50 EDT) NNTP-Posting-Date: Sat, 26 Aug 2006 09:34:50 EDT Organization: Road Runner Xref: g2news2.google.com comp.lang.ada:6392 Date: 2006-08-26T13:34:50+00:00 List-Id: "Dmitry A. Kazakov" wrote in message news:1gx5jdfxrewj6.19ufu2gqaakge.dlg@40tude.net... > 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. I want to avoid this. How about: protected type Event is entry Wait; procedure Signal; private: Arrived : Boolean := False; entry Wait_More; end Event; protected body Event is entry Wait when not Arrived is requeue Wait_More; end Wait; procedure Signal is begin Arrived := True; end Signal; entry Wait_More when Arrived is Arrived := Wait_More'Count > 0; end Wait_More; end Event;