comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Problem with task component
Date: Wed, 19 Sep 2012 12:44:46 -0700 (PDT)
Date: 2012-09-19T12:44:46-07:00	[thread overview]
Message-ID: <476e1044-2371-4a8a-b0bf-2590bdc0b98d@googlegroups.com> (raw)
In-Reply-To: <m2ehlx50vk.fsf@pushface.org>

On Wednesday, September 19, 2012 11:22:08 AM UTC-7, Simon Wright wrote:
> If a Limited_Controlled type has a component of a task type, is it wrong
> to call an entry of the task from Initialize? When I do, the caller
> blocks.
> 
>    package Chips is
> 
>       type Chip is limited private;
> 
>    private 
> 
>       task type Polling_Task (For_Chip : not null access Chip) is
>          entry Start;
>          entry Stop;
>       end Polling_Task;
> 
>       type Chip is new Ada.Finalization.Limited_Controlled with record
>          Polling_Interval : Duration := 0.1; 
>          Poller           : Polling_Task (For_Chip => Chip'Access);
>       end record;
> 
>       overriding
>       procedure Initialize (C : in out Chip);
> 
> ...
> 
>    package body Chips is
> 
>       task body Polling_Task is
>       begin
>          accept Start;
>          ...
>       end Polling_Task;
> 
>       overriding
>       procedure Initialize (C : in out Chip)
>       is
>       begin
>          C.Poller.Start;      <=========== sticks here
>       end Initialize;
> 
> ...
> 
> If the task won't start executing until its instance is completely
> elaborated and initialized, I don't need the entry Start in any case.

I think the relevant rules are spelled out in 9.2.  This specifies when a task is *activated*, and a task can't accept an entry call until it's been activated.  For a task created by an allocator (including a task that's a component of an allocated object), the task activation is the last thing that the allocator does (and 7.6(12) confirms that it will happen after Initialize).  For a task created by a standalone object, e.g.

   procedure P is
      C : Chip;
      X1 : Some_Other_Object;
      X2 : Another_Object;
      ...
   begin
      ...

C.Poller won't get activated until *all* the declared objects have been initialized, including X1 and X2.

So I think it's always the case that a task won't be activated until the outermost object that encloses it have been completely initialized.  So it looks like you don't need Start.

                            -- Adam



      parent reply	other threads:[~2012-09-19 19:44 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-19 18:22 Problem with task component Simon Wright
2012-09-19 18:48 ` Dmitry A. Kazakov
2012-09-19 20:40   ` Simon Wright
2012-09-19 21:11     ` Dmitry A. Kazakov
2012-09-19 21:48       ` Simon Wright
2012-09-24  5:28         ` J-P. Rosen
2012-09-24  8:23           ` Simon Wright
2012-09-24 13:37             ` J-P. Rosen
2012-09-24 14:17               ` Simon Wright
2012-09-24 17:53               ` Robert A Duff
2012-09-24 20:40                 ` J-P. Rosen
2012-09-24 15:44             ` Adam Beneschan
2012-09-24 16:13               ` AdaMagica
2012-09-24 16:43                 ` Adam Beneschan
2012-09-24 16:29               ` Dmitry A. Kazakov
2012-09-24 20:49                 ` J-P. Rosen
2012-09-25  7:35                   ` Dmitry A. Kazakov
2012-09-25 17:52                     ` J-P. Rosen
2012-09-25 18:35                       ` Dmitry A. Kazakov
2012-09-25 19:22                         ` J-P. Rosen
2012-09-26  7:27                           ` Dmitry A. Kazakov
2012-09-26 11:49                             ` Georg Bauhaus
2012-09-26 14:13                               ` Dmitry A. Kazakov
2012-09-19 19:44 ` Adam Beneschan [this message]
replies disabled

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