comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Tasking without Protected Objects.
Date: Tue, 31 Jan 2017 18:40:27 +0100
Date: 2017-01-31T18:40:27+01:00	[thread overview]
Message-ID: <o6qi34$8o9$1@dont-email.me> (raw)
In-Reply-To: <095bc904-c60a-4521-a1a2-8f8b095a4b53@googlegroups.com>

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


  parent reply	other threads:[~2017-01-31 17:40 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-31 14:33 Tasking without Protected Objects patrick
2017-01-31 14:52 ` Dmitry A. Kazakov
2017-01-31 16:47 ` J-P. Rosen
2017-01-31 16:53 ` Björn Lundin
2017-01-31 17:53   ` patrick
2017-01-31 17:40 ` Jeffrey R. Carter [this message]
2017-01-31 17:55   ` patrick
replies disabled

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