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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: Select + Accept syntax question Date: Sat, 27 Aug 2016 16:22:18 -0700 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <60637c3a-c699-4e4c-9fd3-1a081cb6152c@googlegroups.com> <5fef75a7-2232-472e-a4e0-03921e1b5eb9@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Date: Sat, 27 Aug 2016 23:22:26 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="d7c030f56102b58a2c16dea977db88bb"; logging-data="20774"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18A2FBph8UsG+IEKqDuPYuQDfx80L2pVd0=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 In-Reply-To: <5fef75a7-2232-472e-a4e0-03921e1b5eb9@googlegroups.com> Cancel-Lock: sha1:cHtAYJCX6o1pGDThUAmOXhsm9Xs= Xref: news.eternal-september.org comp.lang.ada:31614 Date: 2016-08-27T16:22:18-07:00 List-Id: On 08/27/2016 12:48 PM, Andrew Shvets wrote: > On Saturday, August 27, 2016 at 3:36:35 PM UTC-4, Jeffrey R. Carter wrote: >> >> So the 1st thing after "select [guard]" or "or [guard]" has to be an accept, >> delay, or terminate statement. > > I see, thank you. Your next question, and what Holsti's was trying to get you to consider (I think), is why it's defined this way. It's important to remember that a selective accept can have more than 1 open accept alternative. An example of this is given at the end of ARM 9.7.1: 24 task body Server is Current_Work_Item : Work_Item; begin loop select accept Next_Work_Item(WI : in Work_Item) do Current_Work_Item := WI; end; Process_Work_Item(Current_Work_Item); or accept Shut_Down; exit; -- Premature shut down requested or terminate; -- Normal shutdown at end of scope end select; end loop; end Server; Now, suppose we put a Put_Line immediately prior to each accept, and that such a statement were legal. When the task reaches the select, how does it decide which Put_Line to execute? When does it make that decision? When does it execute the chosen Put_Line? Remember, there may be calls waiting to either, both, or neither of the entries. Now, if you're going to allow one statement there, you might as well allow 2, and if you allow 2, you might as well allow 3, and if you allow 3, you might as well allow any sequence of statements. Such a change would make the compiler writer's job harder, as the compiler would have to search through the statements to find the accept (or delay) that the task should use to decide if it can select that branch. There might be multiple accepts, for multiple entries, in different branches of an if. While it's a general rule of language design that ease of use should have priority over ease of compiler writing, there are limits to how difficult it can be to write a compiler for a language. In this case, it doesn't seem that this feature would let you do anything you can't do without it, so the extra complexity doesn't seem justified. Another consideration is that, if the sequence of statements is long, at some point down the line someone might mistakenly put an accept or delay in the sequence, creating a logic error that might be difficult to find. Your example is not really a good use of the selective accept, as it would be better written accept Input ... loop accept Retrieve ... end loop; This version is much clearer and easy to understand. It also eliminates the use of a magic value. Since the introduction of protected objects in Ada 95, the use of task entries and rendezvous is less common, with many tasks communicating through POs. If what I've written above is all your task does, it would be much better implemented as a PO. I presume you're trying to learn about selective accepts. A good example for that might be the concurrent Sieve of Eratosthenes, which sets up a pipeline of tasks, each holding a discovered prime eliminating candidates that are multiples of its prime. After all the potential candidates have been sieved, each task in turn should be instructed to do something interesting with its prime, such as output it. -- Jeff Carter "Monsieur Arthur King, who has the brain of a duck, you know." Monty Python & the Holy Grail 09