comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Advice, tasking and hardware
Date: Sat, 28 May 2016 17:45:29 +0200
Date: 2016-05-28T17:45:29+02:00	[thread overview]
Message-ID: <nicef4$77j$1@gioia.aioe.org> (raw)
In-Reply-To: 8a5c6387-b476-4332-b0c9-611cbecd64b3@googlegroups.com

On 2016-05-28 16:38, Shark8 wrote:
> On Friday, May 27, 2016 at 2:27:37 PM UTC-6, Dmitry A. Kazakov wrote:
>> On 2016-05-27 21:13, Shark8 wrote:
>>> On Friday, May 27, 2016 at 1:50:50 AM UTC-6, Dmitry A. Kazakov wrote:
>>>> 6. Task entries cannot return unconstrained objects.
>>>
>>> This can be worked around:
>>>    We can add to the previous task the following:
>>> 	    Entry Data( Item : out Natural );
>>> 	    Entry Data( Item : out String );
>>
>> This is a very low-level and very fragile design. Consider ensuring that
>> nothing comes between querying the length and the body that could change
>> the string.
>
> That's actually easy to do with Ada's tasking:
> 		select
> 		    accept Done do
> 			Finished:= True;
> 		    end Done;
> 		or
> 		    accept Get (Data : in String) do
> 			Internal_Data:= String_Holder.To_Holder( Data );
> 		    end Get;
> 		or
> 		    accept Put do
> 			Ada.Text_IO.Put_Line( "DATA: "& Internal_Data.Element );
> 		    end Put;
> 		or
> 		    accept Data (Item : out Natural) do
> 			Item:= Internal_Data.Element'Length;
> 		    end Data;
> 		    accept Data (Item : out String) do
> 			Item:= Internal_Data.Element;
> 		    end Data;

You have a deadlock here when the order of calls is violated, e.g. when 
the caller does not call second Data entry.

>> Then consider a possibility that the caller of a
>> get-length request dies prematurely, or that another task steals the
>> string body and so on.
 >
> Again, precluded by the construction of the select statement shown above.

How do you preclude the caller from not calling the second Data entry?

> Once the task accepts a get-length it *MUST* next accept a get-data,
> so if multiple threads call the get-data then only one gets processed
> and that one is the only one that can then be accepted for a get-data
> because all the rest are waiting on get-length to be serviced.

That happen only if other tasks call Data entries in the exact same 
order. Which is why this is fragile.

The proper design of an Ada task is that *all* declared entries were 
callable in any task state. So if a certain order need to be enforced it 
is better done with barriers than with replicating accept statements and 
nesting selects.

> And tasking shows itself to be a higher-level construct; sure,

Not really. First of all, are you talking about the level of a language 
construct or about the level of a concurrent programming pattern? That is:

1. task type vs protected object type
2. semaphore vs monitor

It is frequently said that Ada concurrent programming primitives are 
higher level. The meaning of this is that they allow implementation of 
other primitives (event, mutex etc) and are integrated into the language 
control flow and type system.

Claiming that tasks are higher level than protected objects or reverse 
is meaningless.

> protected objects have their place, but they *AREN'T* capable of
> directly mapping to a protocol w/o forcing the manual creation of barriers.

As you see it is a quite bad idea to map protocol this way. When dealing 
with protocols, error handing is more important than protocol 
implementation itself. The latter is pretty much trivial. The former is 
what makes software reliable or not.

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


  reply	other threads:[~2016-05-28 15:45 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-25 21:24 Advice, tasking and hardware patrick
2016-05-26  1:09 ` Jeffrey R. Carter
2016-05-26  8:13   ` Simon Wright
2016-05-26  7:26 ` Dmitry A. Kazakov
2016-05-26 16:41   ` patrick
2016-05-26 17:56     ` Dmitry A. Kazakov
2016-05-26 20:35     ` Jeffrey R. Carter
2016-05-26 19:35   ` Jeffrey R. Carter
2016-05-26 20:51     ` patrick
2016-05-27  7:50     ` Dmitry A. Kazakov
2016-05-27 18:00       ` Simon Wright
2016-05-27 19:06       ` Jeffrey R. Carter
2016-05-27 22:05         ` Randy Brukardt
2016-05-27 23:09           ` Jeffrey R. Carter
2016-05-27 19:13       ` Shark8
2016-05-27 20:27         ` Dmitry A. Kazakov
2016-05-27 22:27           ` Randy Brukardt
2016-05-28  6:49             ` Dmitry A. Kazakov
2016-05-28 14:38           ` Shark8
2016-05-28 15:45             ` Dmitry A. Kazakov [this message]
2016-05-28  0:25 ` rieachus
2016-05-28  1:57   ` patrick
2016-05-28  4:13   ` Jeffrey R. Carter
2016-06-01 14:37     ` rieachus
2016-06-01 19:09       ` Dmitry A. Kazakov
2016-06-06  3:33         ` rieachus
2016-06-06  7:18           ` Dmitry A. Kazakov
2016-06-07 16:53             ` rieachus
2016-06-07 20:21               ` Dmitry A. Kazakov
2016-06-08  4:06                 ` rieachus
2016-06-08  7:29                   ` Dmitry A. Kazakov
2016-06-08 12:56                     ` rieachus
2016-06-08  0:19               ` Dennis Lee Bieber
replies disabled

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