From: "DuckE" <nospam_steved94@home.com>
Subject: Re: Question on using protected objects
Date: Sat, 29 Sep 2001 12:30:26 GMT
Date: 2001-09-29T12:30:26+00:00 [thread overview]
Message-ID: <C9jt7.52545$QK.35535895@news1.sttln1.wa.home.com> (raw)
In-Reply-To: 3BB56747.D60CA49F@acm.org
"Jeffrey Carter" <jrcarter@acm.org> 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
next prev parent reply other threads:[~2001-09-29 12:30 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-09-29 3:45 Question on using protected objects DuckE
2001-09-29 6:16 ` Jeffrey Carter
2001-09-29 12:30 ` DuckE [this message]
2001-09-29 14:20 ` Jeff Creem
2001-09-29 15:09 ` DuckE
2001-09-29 17:24 ` Ehud Lamm
2001-09-29 17:29 ` Tucker Taft
2001-09-29 19:01 ` DuckE
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox