comp.lang.ada
 help / color / mirror / Atom feed
* Tasking without Protected Objects.
@ 2017-01-31 14:33 patrick
  2017-01-31 14:52 ` Dmitry A. Kazakov
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: patrick @ 2017-01-31 14:33 UTC (permalink / raw)


Hi Everyone

I haven't been able to program much over the past month or two, what I have written in Ada are toy sized.

For fun I have been trying to restrict myself to Ada 83 with the use of Pragma Ada_83 .

I am assuming that if Ada 83 sucked so bad then there would have been an Ada 84 revision not Ada 95.

I don't think I need very complex tasking. I don't think I need one task to call another, I just need the main task/thread to communicate with the other tasks. I am trying not to use the protected object feature from Ada 95, I am hoping shared variables will work.

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.

Thanks for reading-Patrick


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Tasking without Protected Objects.
  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
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Dmitry A. Kazakov @ 2017-01-31 14:52 UTC (permalink / raw)


On 31/01/2017 15:33, patrick@spellingbeewinnars.org wrote:

> 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?

It cannot unless variables access is atomic (Pragma Atomic).

P.S. Atomic is a necessary but not sufficient exclusion requirement. 
E.g. it is insufficient for incrementing shared variables.

P.P.S. See "monitor" (the access exclusion model suitable for Ada 83 tasks):

    https://en.wikipedia.org/wiki/Monitor_(synchronization)

P.P.P.S. Protected objects are not superior to rendezvous. There are 
cases when one model works better than another and conversely.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Tasking without Protected Objects.
  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:40 ` Jeffrey R. Carter
  3 siblings, 0 replies; 7+ messages in thread
From: J-P. Rosen @ 2017-01-31 16:47 UTC (permalink / raw)


Le 31/01/2017 à 15:33, patrick@spellingbeewinnars.org a écrit :
> I don't think I need very complex tasking. I don't think I need one
> task to call another, I just need the main task/thread to communicate
> with the other tasks.

Rendezvous are a nice way to communicate between tasks. It was the only
way in Ada83, but it's still very convenient when tasks want to talk to
each other.

If you communicate through global variables, you'll still need a basic
synchronization for the main task to know when the data is available.
This could be as simple as including the server tasks in a block
statement: when the main program leaves the block, the local tasks are
necessarily terminated, and therefore data are stable.

-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Tasking without Protected Objects.
  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
  3 siblings, 1 reply; 7+ messages in thread
From: Björn Lundin @ 2017-01-31 16:53 UTC (permalink / raw)


On 2017-01-31 15:33, patrick@spellingbeewinnars.org wrote:
> Hi Everyone
> 
> I haven't been able to program much over the past month or two, what I have written in Ada are toy sized.
> > For fun I have been trying to restrict myself to Ada 83 with the use of Pragma Ada_83 .
> 
> I am assuming that if Ada 83 sucked so bad then there would have been an Ada 84 revision not Ada 95.
> 
> I don't think I need very complex tasking. I don't think I need one task to call another,
> I just need the main task/thread to communicate with the other tasks. 
> I am trying not to use the protected object feature from Ada 95,
> I am hoping shared variables will work.
> 

A common pattern in our old code was to have a serializing tasks.
That is a task that today would have been written as a protected object.

It held the data in local structures - perhaps in its body or in a
package body that only this task could access.

Then, the rest of the tasks as well as the main thread,
accessed the data via the serialization task.


-- 
--
Björn

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Tasking without Protected Objects.
  2017-01-31 14:33 Tasking without Protected Objects patrick
                   ` (2 preceding siblings ...)
  2017-01-31 16:53 ` Björn Lundin
@ 2017-01-31 17:40 ` Jeffrey R. Carter
  2017-01-31 17:55   ` patrick
  3 siblings, 1 reply; 7+ messages in thread
From: Jeffrey R. Carter @ 2017-01-31 17:40 UTC (permalink / raw)


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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Tasking without Protected Objects.
  2017-01-31 16:53 ` Björn Lundin
@ 2017-01-31 17:53   ` patrick
  0 siblings, 0 replies; 7+ messages in thread
From: patrick @ 2017-01-31 17:53 UTC (permalink / raw)


Thanks yet again Dmitry

Thanks J-P and Björn

This is all very helpful.

I think if I create a local task variable and use a select that has an accept to return the data and a delay to timeout and do something useful, things should be good.

-Pat

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Tasking without Protected Objects.
  2017-01-31 17:40 ` Jeffrey R. Carter
@ 2017-01-31 17:55   ` patrick
  0 siblings, 0 replies; 7+ messages in thread
From: patrick @ 2017-01-31 17:55 UTC (permalink / raw)


thanks very much Jeffery.

Great example

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-01-31 17:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2017-01-31 17:55   ` patrick

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