comp.lang.ada
 help / color / mirror / Atom feed
* task pointer
@ 1997-10-20  0:00 Paul Van Gorp
  1997-10-25  0:00 ` Balmacara9
  1997-11-01  0:00 ` Matthew Heaney
  0 siblings, 2 replies; 3+ messages in thread
From: Paul Van Gorp @ 1997-10-20  0:00 UTC (permalink / raw)



I have this problem I want to try to over come, consider..

task type t1 is
	entry a;
	entry done;
end t1;

task type t2 is
	entry a(** access to type t1 **);
	entry b;
end t2;

task body t1 is
T: t2;

begin
	loop
		select
			accept a(**pointer to me**);
			T.b;
			...
		or
			accept done;
			...
		end select;
	end loop;
end t1;

task body t2 is
	C: **task t1 pointer**
begin
	loop
		select
			accept a(**task pointer**) do
				C := task pointer;
			end;
			...
			*task pointer*.done;
		or
			...
end t2;

How would I go about passing the task pointer ? I read in DejaNews where
someone put up a similar question about equivalent to C++'s *this
pointer, and their response suggested to use the type name as the this
pointer.

I tried this and got a gnat bug message when I tried to use the
Unchecked_Access' command!

Does anyone have a workaround ?

Thanks, Paul




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

* Re: task pointer
  1997-10-20  0:00 task pointer Paul Van Gorp
@ 1997-10-25  0:00 ` Balmacara9
  1997-11-01  0:00 ` Matthew Heaney
  1 sibling, 0 replies; 3+ messages in thread
From: Balmacara9 @ 1997-10-25  0:00 UTC (permalink / raw)



There is probably an easier way to do this through the system programming
 annex.  I am much more familiar with Ada83 so this is an Ada83 type of
 solution.

>task type t1; -- incomplete type declaration
>
>type t1_ptr is access t1;
>
>task type t1 is
>                   entry start(**acess to type t1**);
>	entry a;
>	entry done;
>end t1;
>
>task type t2 is
>	entry a(** access to type t1 **);
>	entry b;
>end t2;
>
>
>task body t1 is
>                 T: t2;
>                  Self : t1_ptr;
>begin
>                   accept start(**acess to type t1**);
>                       Self := **acess to type t1**;
>
>	loop
>		select
>			T.a(Self);
>			T.b;
>			...
>		or
>			accept done;
>			...
>		end select;
>	end loop;
>end t1;
>
>task body t2 is
>	Parent: **task t1 pointer**
>begin
>	loop
>		select
>			accept a(**task pointer**) do
>				Parent := task pointer;
>			end;
>			...
>			*task pointer*.done;
>		or
>			...
>end t2;

Starting the task would look like this;

Task1 : t1_ptr := new t1;

Task1.Start(task1);

This is ugly, but it should work.  In Ada95 you may be able pass around task
 ids as opposed to access types.








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

* Re: task pointer
  1997-10-20  0:00 task pointer Paul Van Gorp
  1997-10-25  0:00 ` Balmacara9
@ 1997-11-01  0:00 ` Matthew Heaney
  1 sibling, 0 replies; 3+ messages in thread
From: Matthew Heaney @ 1997-11-01  0:00 UTC (permalink / raw)



In article <344AA999.1AB2@eelab.su.oz.au>, Paul Van Gorp
<paulvg@eelab.su.oz.au> wrote:

You could just declare them as nested tasks, ie

task T1 is
   entry E1;
end;

task body T1 is

   task T2 is
      entry E2;
   end;

   task body T2 is
   begin
      ...
   end;

begin
...
end;

Won't that give each task visibility to the other?

One sign that you really have a single abstraction is that the 2 tasks each
call each other (a dangerous thing though - easy to get deadlock).  The
nesting captures this dependency nicely.

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271




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

end of thread, other threads:[~1997-11-01  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-10-20  0:00 task pointer Paul Van Gorp
1997-10-25  0:00 ` Balmacara9
1997-11-01  0:00 ` Matthew Heaney

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