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,d154e1596a6ac2d9 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: Newbie: Task parametering Date: 16 Oct 2005 17:53:07 -0700 Organization: http://groups.google.com Message-ID: <1129510387.675070.134750@g14g2000cwa.googlegroups.com> References: <4352ef15$0$28225$5a62ac22@per-qv1-newsreader-01.iinet.net.au> NNTP-Posting-Host: 69.170.70.49 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1129510393 18436 127.0.0.1 (17 Oct 2005 00:53:13 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 17 Oct 2005 00:53:13 +0000 (UTC) User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20040913 Firefox/0.10,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: g14g2000cwa.googlegroups.com; posting-host=69.170.70.49; posting-account=SqOfxAwAAAAkL81YAPGH1JdBwpUXw9ZG Xref: g2news1.google.com comp.lang.ada:5733 Date: 2005-10-16T17:53:07-07:00 List-Id: Andrew Price wrote: > Hello all, > > I need to initialise some tasks with a few parameters when I instantiate > them. After looking at > http://www.adaic.com/docs/95style/html/sec_6/6-1-3.html it seems the > best way to do this is using an access type discriminant to pass a > record to the tasks. > > With that in mind, I created this record type; > > type Task_Data is > record > Name : aliased String(1..8); > Period : aliased Duration; > Repetitions : aliased Integer; > end record; > > > and then in the main part of my program I use it like this; > > type Task_Handle is access A_Task; -- used to point to the task > Another_Task : Task_Handle; > type Data_Handle is access Task_Data; -- used to point to its data > Data_For_Task : Data_Handle; > > begin -- The main prog will now spawn three of the above tasks > > -- Parameterise the first task and then start it. > Data_For_Task := new Task_Data; > Data_For_Task.Name := "Task A "; > Data_For_Task.Period := 0.5; > Data_For_Task.Repetitions := 5; > Another_Task := new A_Task(Data_For_Task); > > So while this approach works, I can't help but feel that I'm going about > this in a 'long winded' way (especially coming from a mostly C background). > > Is there are neater way of putting the data into the Task_Data records? > Or is there an better approach to the whole task parameterisation I > should consider? > > Now is probably a good time to add the disclaimer that this is part of a > lab work exercise for a course I'm currently undertaking at university. There is a little roblem with your approach. It does not actually initialize the task. The task begins running before the values are set. You are likely to encounter a race condition with your approach. True initialization can be achieved by providing a discriminant to the task. On the other hand, you may not need a true initialization. Instead, you may simply want the task to begin by accepting an entry that passes in all the values you need to set before the task does anything else. Read about the concepts of discriminants and task entries. You should then be able to decide which approach best fits your needs. Jim Rogers