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,36bf044dcba542cc X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-09-29 05:30:27 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!feed.textport.net!out.nntp.be!propagator-SanJose!news-in-sanjose!newshub2.rdc1.sfba.home.com!news.home.com!news1.sttln1.wa.home.com.POSTED!not-for-mail From: "DuckE" Newsgroups: comp.lang.ada References: <3BB56747.D60CA49F@acm.org> Subject: Re: Question on using protected objects X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Message-ID: Date: Sat, 29 Sep 2001 12:30:26 GMT NNTP-Posting-Host: 24.248.45.203 X-Complaints-To: abuse@home.net X-Trace: news1.sttln1.wa.home.com 1001766626 24.248.45.203 (Sat, 29 Sep 2001 05:30:26 PDT) NNTP-Posting-Date: Sat, 29 Sep 2001 05:30:26 PDT Organization: Excite@Home - The Leader in Broadband http://home.com/faster Xref: archiver1.google.com comp.lang.ada:13510 Date: 2001-09-29T12:30:26+00:00 List-Id: "Jeffrey Carter" wrote in message news:3BB56747.D60CA49F@acm.org... > What does your compiler say? (Hint: I suggest using GNAT with the -gnaty > option.) The compiler is perfectly happy with this. It even "appears" to do exactly what I want. If I were programming in C, that's as far as I would go before using this construct. In Ada I try to avoid the "try it and see if it works" mode of operation since it sometimes leads to unpredictable results. Here is the complete test program that "appears" do do exactly what I want, I just don't know whether it is appropriate to use the "defining_identifier" as part of the "entry_barrier" (LRM 9.5.2): WITH Ada.Text_Io; PROCEDURE TestProtType IS nbWaiters : CONSTANT := 4; SUBTYPE aWaitSelect IS INTEGER RANGE 1 .. nbWaiters; TYPE aWaitArray IS ARRAY( aWaitSelect ) OF BOOLEAN; PROTECTED TYPE aQueueingType IS ENTRY GetEntry( waitSelect : aWaitSelect; getResult : out Integer ); PROCEDURE Release( waitSelect : aWaitSelect ); PRIVATE ENTRY WaitForIt( aWaitSelect ); waitFlag : aWaitArray := ( OTHERS => FALSE ); counter : Natural := 0; END aQueueingType; PROTECTED BODY aQueueingType IS PROCEDURE Release( waitSelect : aWaitSelect ) IS BEGIN waitFlag( waitSelect ) := TRUE; END Release; ENTRY GetEntry( waitSelect : aWaitSelect; getResult : out Integer ) WHEN GetEntry'COUNT = 0 IS BEGIN getResult := counter; counter := counter + 1; REQUEUE WaitForIt( waitSelect ); END GetEntry; ENTRY WaitForIt ( FOR waitSelect IN aWaitSelect ) WHEN waitFlag( waitSelect ) IS BEGIN waitFlag( waitSelect ) := FALSE; END WaitForIt; END aQueueingType; qFlag : aQueueingType; TASK TYPE aWaiter( waitSelect : aWaitSelect ) IS END aWaiter; TASK BODY aWaiter IS getResult : Integer; BEGIN qFlag.GetEntry( waitSelect, getResult ); Ada.Text_Io.Put_Line( "Waiter " & aWaitSelect'IMAGE(waitSelect) & ", " & Integer'IMAGE( getResult ) & " released!" ); END aWaiter; TYPE aWaiterPtr IS ACCESS ALL aWaiter; nbWaitTasks : CONSTANT := 3; BEGIN FOR lpCnt IN 1 .. nbWaitTasks LOOP FOR ii IN aWaitSelect'RANGE LOOP DECLARE waitPtr : aWaiterPtr; BEGIN waitPtr := NEW aWaiter( ii ); END; END LOOP; END LOOP; FOR lpCnt IN 1 .. nbWaitTasks LOOP FOR ii IN aWaitSelect'RANGE LOOP DELAY 1.0; qFlag.Release( ii ); END LOOP; END LOOP; DELAY 1.0; END TestProtType; > > -- > Jeff Carter > "You cheesy lot of second-hand electric donkey-bottom biters." > Monty Python & the Holy Grail