comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Advice, tasking and hardware
Date: Fri, 27 May 2016 09:50:13 +0200
Date: 2016-05-27T09:50:13+02:00	[thread overview]
Message-ID: <ni8u8j$1h74$1@gioia.aioe.org> (raw)
In-Reply-To: ni7iue$v9b$1@dont-email.me

On 26/05/2016 21:35, Jeffrey R. Carter wrote:
> On 05/26/2016 12:26 AM, Dmitry A. Kazakov wrote:
>>
>> If you want interlocking for doing blocking calls use a mutex etc. A mutex
>> implementation based on protected objects is two actions: Seize and Release.
>
> To the OP: This is terrible advice. One should only use a low-level mechanism
> such as a semaphore when one can't achieve what one needs with the high-level
> mechanisms provided by the language: tasks and protected objects.

In practice it is not just a semaphore. The implementation protected 
object frequently carries higher level functions, e.g. protecting a 
queue of requests.

BTW an explicit queue is used only in the case of asynchronous 
processing of requests.

The rule of thumb is that if all requests are done synchronously to the 
caller, no task is used, only a protected interlocking object is. The 
entry of the protected object serves as a queue. If some requests are 
asynchronous, a task and a protected object are necessary.

A task alone is a rare case.

> Since there's
> no way for the compiler to know that the subprogram is potentially blocking,
> there's no reason not to put the call in a PO and make use of the high-level
> mutual exclusion it provides. Even if the system has problems with the call
> being in a protected operation, it's better to put a request for the call on a
> protected queue and have a task that gets the requests from the queue and makes
> the calls than to use a semaphore.

Tasks and protected objects have advantages and disadvantages. Regarding 
tasks the disadvantages are:

1. You need a task.

2. Ada tasks are difficult to compose, especially to have encapsulated 
tasks. Task components do not work in practical cases, so a pointer to 
the task will be required.

3. Ada tasks have problems with termination. The termination alternative 
design makes is unusable in most cases. There must be Shut_Down entry 
instead and a caller of it as well.

4. Task objects are tricky to deallocate. You must wait for task 
termination before calling Unchecked_Deallocation on it. Waiting within 
a Finalize is no fun.

5. Tasks entries have parameter passing problems. If you don't handle 
everything in the rendezvous in order to release the caller as soon as 
possible, you need to copy parameters and store them locally. The design 
of the select statement prevents doing this in a structured way. E.g.

    select
       accept String_Call (Text : String) do
          Local_Text := Text; -- Accept scope
       end;
       declare -- Handler's scope
          Local_Text : String -- This does not work!
       begin
          -- Process Local_Text
       end;
    or accept ...

6. Task entries cannot return unconstrained objects.

7 + 5-6. Task design requires sometimes a very complex state machine 
implementation to remember the order of accepted entries. It cannot be 
decomposed in a structured way because tasks are not composable. 
Protected objects have this too but they are somewhat simpler because 
some handling of the states could be done at the caller's side.

So in the end there could be a lot more low-level stuff regarding task 
maintenance, result passing, elaboration and finalization.

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

  parent reply	other threads:[~2016-05-27  7:50 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 [this message]
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
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