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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d6611f5dd578d5e1 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-05-05 13:32:38 PST Path: newsfeed.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!logbridge.uoregon.edu!newsfeed.direct.ca!look.ca!newsfeed1.earthlink.net!newsfeed.earthlink.net!newsmaster1.prod.itd.earthlink.net!newsread2.prod.itd.earthlink.net.POSTED!not-for-mail Message-ID: <3AF46357.59923199@acm.org> From: Jeffrey Carter X-Mailer: Mozilla 4.7 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Protected entries requeueing themselves References: <9cv3j3$h5m$1@news.netmar.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Sat, 05 May 2001 20:32:40 GMT NNTP-Posting-Host: 63.178.187.73 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.prod.itd.earthlink.net 989094760 63.178.187.73 (Sat, 05 May 2001 13:32:40 PDT) NNTP-Posting-Date: Sat, 05 May 2001 13:32:40 PDT Organization: EarthLink Inc. -- http://www.EarthLink.net X-Received-Date: Sat, 05 May 2001 13:31:05 PDT (newsmaster1.prod.itd.earthlink.net) Xref: newsfeed.google.com comp.lang.ada:7210 Date: 2001-05-05T20:32:40+00:00 List-Id: adam@irvine.com wrote: > > protected PR is > entry E1 (Min_Count : in integer; Result : out integer); > procedure PROC1; > private > Count : integer := 0; > end PR; > > Suppose PROC1 increments Count. The intent of E1 is for each calling > task to wait until Count has been incremented past whichever point > that task desires. This is illegal: > > entry E1 (Min_Count : in integer; Result : out integer) > when Min_Count >= Count is ... > > Intuitively, it seems like this should work: > > entry E1 (Min_Count : in integer; Result : out integer) when True is > begin > if Min_Count < Count then > requeue E1; > end if; > Result := ... > > with the intended effect being that after PROC1 is called, all the > entries on E1 will be executed to check their Min_Count, and those > that don't meet the requirement will requeue themselves, while those > that do will complete. > > But I don't think it works. As I read 9.5.3, it seems that when E1 > requeues itself, the protected action continues, and this includes > servicing entry queues, and since "servicing of entry queues continues > until there are no open entries with queued calls" (9.5.3(18)), but > this entry will always be open and there will always be a queued call > on it, since the task keeps requeueing itself on the entry. Thus, the > result of this is an infinite loop. That's correct. No one can get the protected object's lock to execute Proc1, so Count will never change, and this is an infinite loop unless there are other tasks queued on E1 and a task that is not requeued changes Count. > I recognize that 9.5.2(31) suggests using a private entry, but I'm not > sure how. If the barrier on the private entry is "when True", the > same problem occurs; but I can't think what other barrier could be put > on the private entry to make things work. > > Any suggestions? How would you implement something like this to > achieve the intended effect? Or is my understanding of 9.5.3 > incorrect? You would use something like protected PR is entry E1 (Min_Count : in Natural; Result : out integer); procedure Increment; private -- PR entry E2 (Min_Count : in Natural; Result : out Integer); Count : Natural := 0; Max_Desired_Count : Integer := -1; end PR; protected body PR is procedure Increment is begin -- Increment Count := Count + 1; end Increment; entry E1 (...) when True is begin -- E1 if Min_Count < Count then Max_Desired_Count := Integer'Max (Max_Desired_Count, Min_Count); requeue E2; end if; ... end E1; entry E2 (...) when Count <= Max_Desired_Count is begin -- E2 ... if E2'Count <= 0 then Max_Desired_Count := -1; end if; end E2; end PR; This stores up requests until it can Count is suitable for all stored requests, which is not quite what you were discussing, but has a simpler solution than your problem while still using requeue for preference control. HTH. -- Jeff Carter "Son of a window-dresser." Monty Python & the Holy Grail