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: Tasking without Protected Objects. Date: Tue, 31 Jan 2017 18:40:27 +0100 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <095bc904-c60a-4521-a1a2-8f8b095a4b53@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 31 Jan 2017 17:38:44 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="abc2dd101db02a55eacb1ca8d6873cc0"; logging-data="8969"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18J9hm9FQaIQFkTDn4jbj/dphMnbpilMRs=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 In-Reply-To: <095bc904-c60a-4521-a1a2-8f8b095a4b53@googlegroups.com> Cancel-Lock: sha1:+B8CAaqaflhbHUEzgUAIuQmmx90= Xref: news.eternal-september.org comp.lang.ada:33223 Date: 2017-01-31T18:40:27+01:00 List-Id: On 01/31/2017 03:33 PM, patrick@spellingbeewinnars.org wrote: > > I am assuming that if Ada 83 sucked so bad then there would have been an Ada 84 revision not Ada 95. Ada 83 was a very good language, and better than most of the languages in common use more than 30 years later. > If I have : > > var1 > var2 > var3 > > task1 > task2 > task3 > > and if each tasks only writes to it's variable, task1 -> var1 > > then can the main thread read/write to var1 thru var3 without issues? Could > there be a conflict with the other non-main tasks ? assuming we are not > talking about writing to a file. Not unless you can make the variables atomic. If you can't, then you'll need a "passive task". This is a task that only takes action during a rendezvous. A simple passive task: task type Monitor is entry Put (Value : in Element); entry Get (Value : out Element); end Monitor; tasks body Monitor is Stored : Element := Initial; begin -- Monitor Forever : loop select accept Put (Value : in Element) do Stored := Value; end Put; or accept Get (Value : out Element) do Value := Stored; end Get; or terminate; end select; end loop Forever; end Monitor; Such tasks don't need a thread of control, and some Ada-83 compilers provided ways to tell the compiler not to create a thread of control for passive tasks. Some compiler developers were developing ways to automatically identify passive tasks. Rather than build on that work, the Ada-95 effort introduced protected objects. Protected objects have the advantages that they don't have a thread of control, and they can have functions, and so can return unconstrained values like String. Tasks have the advantage that they can do anything, while protected operations are prohibited from performing potentially blocking actions. -- Jeff Carter "Ah, go away or I'll kill ya." Never Give a Sucker an Even Break 100