comp.lang.ada
 help / color / mirror / Atom feed
From: "jimmaureenrogers@worldnet.att.net" <jimmaureenrogers@worldnet.att.net>
Subject: Re: I don't know what the compiler wants to tell me
Date: 3 Nov 2005 14:39:34 -0800
Date: 2005-11-03T14:39:34-08:00	[thread overview]
Message-ID: <1131057574.589626.320420@g14g2000cwa.googlegroups.com> (raw)
In-Reply-To: <20051103214759.6d049f90@localhost>

Thomas Ruschival wrote:
> Hi Group
> I just wrote a sample program in which I wanted to understand how it works
> with task type and instatiating tasks of that type.
> Now I run into a strange Compiler error I don't understand:
>
> hello2b.adb:48:18: left hand of assignment must not be limited

There is no pre-defined assignment for limited types. It is therefore
forbidden to attempt to assign to a limited type.

Task types are limited types. You cannot assign one task to another.

>
> Basically all I wanted to do is have a task running until another task
> does a rendevouz and interrupts exactly that task. I wanted it
> configurable so I first chose to configure it in the disciminants which
> didn't work.
> Now I pass the task to be controlled at a rendevouz point to
> the controller, this should copy it into a local variable to keep the
> rendevouz as short as possible and then control the task to which the local
> variable points to.... as I write this the question arises: does ada pass
> by value or by reference?
>
> I appreciate any comments on how you do rendevous with task you don't know
> yet at the time of writing, lets say you just know the access points of
> that task type but you want to make rendevous with different instances of
> that type, so you need to tell this either at point where you instantiate
> the task that calls the entry point or at another point you have to tell
> the task which object to meet
>
>
> Thanks
> Thomas Ruschival
>
>
> Here is the code:
> with Text_IO, Calendar;
> use Calendar;
>
> procedure Hello2b is
>
>    task type PrinterTask is
> 	  entry Interrupt;
>    end PrinterTask;
>
>    task type ControlTask is
> 	  entry Start(ToControl : in PrinterTask);
>    end ControlTask;
>
> ------ Hello Task to do the important work of printing "Hello" to
> Console task body PrinterTask is
>       SamplingTime : Duration := 2.0;
>       NextActivation : Calendar.Time ;
> 	  irq  : Boolean := False;
>    begin
>       while Irq = False  -- infinite loop until an external task does
> 						 -- a rendevouz to
> interrupt loop
> 		 -- next activation will be SamplingTime from now
> 		 NextActivation := Clock + SamplingTime;
> 		 -- either interrupt occurs or we wait until
> 		 -- samplingTime is elapsed and print Hello
> 		 select
> 			accept Interrupt;
> 			  Irq := True;
> 		 or
> 			delay until NextActivation;
> 			Text_IO.Put_Line("task running");
> 		 end select;
>       end loop;
>    end PrinterTask;
>
> ------ ControlTask to interrupt the work of a given Task
>    task body ControlTask is
> 	  Controlled : PrinterTask; -- task To be controlled

The variable Controlled is an instance of a limited type.
The variable Controlled creates a PrinterTask upon elaboration of the
ControlTask body.
That PrinterTask instance begins executing as soon as it is scheduled
after its creation.

>    begin
> 	  -- Copy into local variable
> 	  accept Start(ToControl : in PrinterTask) do
> 		 Controlled := ToControl;
> 	  end Start;
>
> 	  delay 60.0; -- wait a minute
> 	 Controlled.Interrupt; -- Now make a rendevouz with the task we
> want to terminate end ControlTask;
>
> -- tasks
>    Printer :  PrinterTask;
>    Controller: ControlTask;
>
> begin
>    Text_IO.Put_Line("Procedure running....");
>    Controller.Start(Printer);
> end Hello2b;

Instead of passing an instance of a task either through a discriminant,

which is forbidden, or through an entry, which also does not work, you
can create an access to task type and pass that through a discriminant
or entry.

task type PrinterTask is
   entry Interrupt;
end PrinterTask;

type Printer_Access is access PrinterTask;

task type ControlTask(ToControl : Printer_Access);

...

You can then create instances of your tasks as follows:

Printer : Printer_Access := new PrinterTask;
Controller : ControlTask(Printer);

Your ControlTask body will have a statement such as:

     ToControl.Interrupt;

Jim Rogers




  reply	other threads:[~2005-11-03 22:39 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-03 20:47 I don't know what the compiler wants to tell me Thomas Ruschival
2005-11-03 22:39 ` jimmaureenrogers [this message]
2005-11-08  8:43   ` Thomas Ruschival
2005-11-08 19:30     ` Ada books (was: I don't know what the compiler wants to tell me) Björn Persson
2005-11-04  5:12 ` I don't know what the compiler wants to tell me Jeffrey R. Carter
2005-11-04  9:14   ` Lurker
2005-11-04 17:55     ` Martin Krischik
2005-11-07  8:32       ` Maciej Sobczak
replies disabled

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