From: Jeffrey Carter <jrcarter@acm.org>
Subject: Re: Suspension_Object problem
Date: Wed, 15 Jan 2003 19:02:01 GMT
Date: 2003-01-15T19:02:01+00:00 [thread overview]
Message-ID: <3E25B01D.7010405@acm.org> (raw)
In-Reply-To: 3E257FD5.8765352C@obs-vlfr.fr
Philippe Laval wrote:
> The following program compiles without error in gnat 3.14p.
> However the line "From H: P is now released" never shows up. What is
> wrong?
>
> -- File Susp_O.adb
> with P_Pkg;
> with H_Pkg;
> procedure Susp_O is
> begin
> null;
> end Susp_O;
> ----------------------------------------------------------------------------------------------
>
> -- File P_Pkg.ads
> with Ada.Synchronous_Task_Control; use Ada.Synchronous_Task_Control;
> package P_Pkg is
> protected type Protected_Lock is
> procedure Set_Lock;
> procedure Release;
> private
> Lock : Suspension_Object;
> end Protected_Lock;
>
> type Lock_Access is access Protected_Lock;
> Attack_Lock : Lock_Access;
>
> task P;
>
> end P_Pkg;
>
> ------------------------------------------------------------------------------------------------
>
> -- File P_Pkg.ads
> package H_Pkg is
> task H;
> end H_Pkg;
> ------------------------------------------------------------------------------------------------
>
> -- File P_Pkg.adb
> with Ada.Text_IO; use Ada.Text_IO;
> package body P_Pkg is
> protected body Protected_Lock is
> procedure Set_Lock is
> begin
> Suspend_Until_True (Lock);
> end Set_Lock;
>
> procedure Release is
> begin
> Set_True (Lock);
> end Release;
> end Protected_Lock;
>
> task body P is
> begin
> Attack_Lock := new Protected_Lock;
> Put_Line ("P is being suspended.");
> Put_Line ("Waiting to be released by H...");
> Attack_Lock.Set_Lock;
>
> Put_Line ("P is now released.");
> end P;
> end P_Pkg;
> ------------------------------------------------------------------------------------------------
>
> -- File H_Pkg.adb
> with Ada.Text_IO; use Ada.Text_IO;
> with P_Pkg;
> package body H_Pkg is
> task body H is
> begin
> delay 1.0;
> P_Pkg.Attack_Lock.Release;
> Put_Line ("From H : P is released now!");
> end H;
> end H_Pkg;
This seems entirely inappropriate. Either your 2 tasks should operate on
a shared Suspension_Object or they should operate on a shared protected
object. Mixing the 2 seems inappropriate, especially as some operations
on Suspension_Objects are intended to be blocking operations, and
therefore illegal to call from a protected object.
I suspect that your problem comes because the call to Suspend_Until_True
blocks P before it completes executing Set_Lock, so it never frees the
protected object to allow H to execute Release.
There is also no need to use access types in this example.
--
Jeff Carter
"Pray that there's intelligent life somewhere up in
space, 'cause there's bugger all down here on earth."
Monty Python's Meaning of Life
prev parent reply other threads:[~2003-01-15 19:02 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-01-15 15:35 Suspension_Object problem Philippe Laval
2003-01-15 15:46 ` Jean-Pierre Rosen
2003-01-15 19:02 ` Jeffrey Carter [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox