From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,abaec53fd41aec4e X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!g14g2000cwa.googlegroups.com!not-for-mail From: "jimmaureenrogers@worldnet.att.net" Newsgroups: comp.lang.ada Subject: Re: I don't know what the compiler wants to tell me Date: 3 Nov 2005 14:39:34 -0800 Organization: http://groups.google.com Message-ID: <1131057574.589626.320420@g14g2000cwa.googlegroups.com> References: <20051103214759.6d049f90@localhost> NNTP-Posting-Host: 209.194.156.4 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1131057580 10852 127.0.0.1 (3 Nov 2005 22:39:40 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 3 Nov 2005 22:39:40 +0000 (UTC) In-Reply-To: <20051103214759.6d049f90@localhost> User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0),gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: g14g2000cwa.googlegroups.com; posting-host=209.194.156.4; posting-account=SqOfxAwAAAAkL81YAPGH1JdBwpUXw9ZG Xref: g2news1.google.com comp.lang.ada:6160 Date: 2005-11-03T14:39:34-08:00 List-Id: 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