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,97f543c7a63b8839 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!newsfeed2.dallas1.level3.net!news.level3.com!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Composing tasks and protected objects Date: 05 Aug 2005 13:49:06 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <87iryk1eic.fsf@mid.deneb.enyo.de> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1123264147 15035 192.74.137.71 (5 Aug 2005 17:49:07 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Fri, 5 Aug 2005 17:49:07 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: g2news1.google.com comp.lang.ada:3987 Date: 2005-08-05T13:49:06-04:00 List-Id: Florian Weimer 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