comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Composing tasks and protected objects
Date: 05 Aug 2005 13:49:06 -0400
Date: 2005-08-05T13:49:06-04:00	[thread overview]
Message-ID: <wccmznwff59.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 87iryk1eic.fsf@mid.deneb.enyo.de

Florian Weimer <fw@deneb.enyo.de> writes:

> Suppose I want to write a selective accept which reads messages from a
> queue, and also support a special entry call to reload the
> configuration.
> 
> Conceptually, this would look like this:
> 
>    task Server is
>       entry Reload_Configuration (Config : Config_Template);
>       entry Shut_DOwn;
>    end Server;
> 
>    task body Server is
>       Current_Message : Message;
> 
>    begin
>       loop
>          select
>             Get (Queue, Current_Message);
>             Process_Message (Current_Message);
> 
>          or
>             accept Reload_Configuration (Config : Config_Template) do
>                Process_Reload (Config);
>             end Reload_Configuration;
> 
>          or
>             accept Shut_Down;
>             exit;       -- Premature shut down requested
> 
>          or
>             terminate;  -- Normal shutdown at end of scope
>          end select;
>       end loop;
>    end Server;
> 
> In short, I want to perform protected entry calls and selective accept
> in parallel.
> 
> Is this possible at all, without writing lots of stupid wrappers?

No.  You cannot mix entry calls and accepts in the same select
statement.  You can't mix entry calls with "terminate", either.

The original Ada 9X design proposed to allow multiple entry calls in a
select, which would solve your main problem, which is waiting on
multiple events.  Your two entries would then become entries of a
protected object, and the above select would call them.  Whoever calls
those two entries would instead call protected procedures that trigger
those entries.

You would have to eliminate the terminate alternative, and use the
Shut_Down mechanism instead.  Or abort the task.

The multi-way call feature was rejected primarily due to perceived
difficulty of implementation, or perceived difficulty of *efficient*
implementation.  I did not agree with that argument.

One workaround is to change the call to Get into an accept
-- i.e. make Get be an entry of this task, and arrange for it
to be called as appropriate.

Another workaround is to implement something like multi-way call
yourself.  Several entries can be shunted through a single entry, with a
bit-mask saying which entry is intended.  Or something like that.  You
could probably create a general-purpose feature by wrapping that mess in
generics.

>...If
> not, what was the justification for not integrating the two language
> features (protected objects/tasks) in this way?

As far as I know, mixing calls and accepts was not considered,
perhaps because protected objects were intended to be a very lightweight
mechanism (compared to task entries and accept statements).

I don't think terminates mixed with calls was considered, either.  It's
not clear what it should mean.  Normally, "terminate" means the task
terminates when there is no possibility that anybody might want to call
the entries the task is waiting on.  This doesn't work in the case of
interrupt entries, but in all other cases, various language rules ensure
that it's true (e.g., a task can only accept its own entries).  But for
calls, the same reasoning doesn't work.

I'd be interested if anybody can give some rules that make sense for
mixing terminate with calls.

- Bob



  reply	other threads:[~2005-08-05 17:49 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-05 17:26 Composing tasks and protected objects Florian Weimer
2005-08-05 17:49 ` Robert A Duff [this message]
2005-08-05 18:09   ` Florian Weimer
2005-08-05 18:26     ` Robert A Duff
2005-08-05 19:20       ` Florian Weimer
2005-08-07  1:27       ` Randy Brukardt
2005-08-08 21:55         ` Robert A Duff
2005-08-06  5:52 ` Jeffrey Carter
2005-08-08  9:52   ` Florian Weimer
2005-08-08 20:50     ` Randy Brukardt
2005-08-08 22:14       ` Robert A Duff
2005-08-06  9:01 ` Dmitry A. Kazakov
replies disabled

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