comp.lang.ada
 help / color / mirror / Atom feed
From: Shark8 <onewingedshark@gmail.com>
Subject: Re: Nested Task Entry Question
Date: Tue, 24 Apr 2018 11:45:21 -0700 (PDT)
Date: 2018-04-24T11:45:21-07:00	[thread overview]
Message-ID: <ece0d5d1-90a8-4b8e-bae3-4a2823f7a429@googlegroups.com> (raw)
In-Reply-To: <3f521db0-5ee2-40ae-95af-26ef6b843722@googlegroups.com>

On Tuesday, April 24, 2018 at 10:57:29 AM UTC-6, NiGHTS wrote:
> I have two tasks: Task P and Task C. Task P creates Task C, but Task C must call entries into Task P. 
> 
> I can't seem to figure out how to make an entry on a parent task executable by a child task.
> 
> I am eternally grateful for your assistance! Thank you!

    Task Type Parent is
	Entry Start;
	Entry Child_Call( Value : Natural );
	Entry Stop;
    End Parent;
    
    Task Type Child( P : not null access Parent ) is
    End Child;
    
    Task Body Child is
    Begin
	Ada.Text_IO.Put_Line( "Inside Child; Setting Parent value.");
	P.Child_Call( 23 );
    End Child;
    
    Task Body Parent is
	Internal : Natural := 77;
    Begin
	accept Start  do
	    Ada.Text_IO.Put_Line( "Starting Parent (Value:" &
			     Natural'Image(Internal) & " )." );
	end Start;
	accept Child_Call (Value : in Natural) do
	    Ada.Text_IO.Put_Line( "Call from child." );
	    Internal := Value;
	end Child_Call;
	accept Stop  do
	    Ada.Text_IO.Put_Line( "Stopping Parent (Value:" &
			     Natural'Image(Internal) & " )." );
	end Stop;
    End Parent;

--...
    Parent_Task.Start;
    -- Hidden Child call happens after Start finishes, due to being queued on entry.
    Parent_Task.Stop;

----------------
Also, note that the putline happens *BEFORE* the output of the Parent-task; this is because the queuing on the entry happens, due to the parent having to wait for the START entry.

  reply	other threads:[~2018-04-24 18:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-24 16:57 Nested Task Entry Question NiGHTS
2018-04-24 18:45 ` Shark8 [this message]
2018-04-24 22:00   ` NiGHTS
2018-04-24 20:47 ` AdaMagica
2018-04-24 20:54   ` AdaMagica
2018-04-24 22:03   ` NiGHTS
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox