comp.lang.ada
 help / color / mirror / Atom feed
* Nested Task Entry Question
@ 2018-04-24 16:57 NiGHTS
  2018-04-24 18:45 ` Shark8
  2018-04-24 20:47 ` AdaMagica
  0 siblings, 2 replies; 6+ messages in thread
From: NiGHTS @ 2018-04-24 16:57 UTC (permalink / raw)


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!


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Nested Task Entry Question
  2018-04-24 16:57 Nested Task Entry Question NiGHTS
@ 2018-04-24 18:45 ` Shark8
  2018-04-24 22:00   ` NiGHTS
  2018-04-24 20:47 ` AdaMagica
  1 sibling, 1 reply; 6+ messages in thread
From: Shark8 @ 2018-04-24 18:45 UTC (permalink / raw)


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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Nested Task Entry Question
  2018-04-24 16:57 Nested Task Entry Question NiGHTS
  2018-04-24 18:45 ` Shark8
@ 2018-04-24 20:47 ` AdaMagica
  2018-04-24 20:54   ` AdaMagica
  2018-04-24 22:03   ` NiGHTS
  1 sibling, 2 replies; 6+ messages in thread
From: AdaMagica @ 2018-04-24 20:47 UTC (permalink / raw)


Am Dienstag, 24. April 2018 18:57:29 UTC+2 schrieb NiGHTS:
> 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.

  declare
    task P is
      entry E;
    end P;
    task body P is
      task C;
      task body C is
      begin
        Put_Line ("calling P");
        P.E;
      end C;
    begin
      accept E;
      Put_Line ("accepted C");
   end P;
  begin
    --delay 1.0;
    Put_Line ("completing");
  end;


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Nested Task Entry Question
  2018-04-24 20:47 ` AdaMagica
@ 2018-04-24 20:54   ` AdaMagica
  2018-04-24 22:03   ` NiGHTS
  1 sibling, 0 replies; 6+ messages in thread
From: AdaMagica @ 2018-04-24 20:54 UTC (permalink / raw)


P and C are executing independently. But C must terminate first so that P can terminate.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Nested Task Entry Question
  2018-04-24 18:45 ` Shark8
@ 2018-04-24 22:00   ` NiGHTS
  0 siblings, 0 replies; 6+ messages in thread
From: NiGHTS @ 2018-04-24 22:00 UTC (permalink / raw)


On Tuesday, April 24, 2018 at 2:45:24 PM UTC-4, Shark8 wrote:
> 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.

My guess is that you meant to instantiate the child task type into the parent declaration area, though forgot to do that. Still I see your point. Thank you for your help.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Nested Task Entry Question
  2018-04-24 20:47 ` AdaMagica
  2018-04-24 20:54   ` AdaMagica
@ 2018-04-24 22:03   ` NiGHTS
  1 sibling, 0 replies; 6+ messages in thread
From: NiGHTS @ 2018-04-24 22:03 UTC (permalink / raw)


On Tuesday, April 24, 2018 at 4:47:58 PM UTC-4, AdaMagica wrote:
> Am Dienstag, 24. April 2018 18:57:29 UTC+2 schrieb NiGHTS:
> > 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.
> 
>   declare
>     task P is
>       entry E;
>     end P;
>     task body P is
>       task C;
>       task body C is
>       begin
>         Put_Line ("calling P");
>         P.E;
>       end C;
>     begin
>       accept E;
>       Put_Line ("accepted C");
>    end P;
>   begin
>     --delay 1.0;
>     Put_Line ("completing");
>   end;

This is an elegant solution. I am very happy that you took the time to write this. Its exactly what I needed! Thank you again.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-04-24 22:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-24 16:57 Nested Task Entry Question NiGHTS
2018-04-24 18:45 ` Shark8
2018-04-24 22:00   ` NiGHTS
2018-04-24 20:47 ` AdaMagica
2018-04-24 20:54   ` AdaMagica
2018-04-24 22:03   ` NiGHTS

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