comp.lang.ada
 help / color / mirror / Atom feed
* Private or public task ?
@ 2010-02-05 20:54 Hibou57 (Yannick Duchêne)
  2010-02-05 20:56 ` Hibou57 (Yannick Duchêne)
                   ` (2 more replies)
  0 siblings, 3 replies; 31+ messages in thread
From: Hibou57 (Yannick Duchêne) @ 2010-02-05 20:54 UTC (permalink / raw)


Hello Ada novel writers,

I'm starting to experiment with Ada tasking, which as I suggest, I've
never used so far (I will need at least it for a Windows API binding
and for a later VST binding... a VST is a kind of software synthesizer
for electronic music).

Let me explain the context before I introduce my though. I was playing
with a source from a tutorial.
This source : http://www.infres.enst.fr/~pautet/Ada95/e_c26_p2.ada
From this tutorial : http://www.infres.enst.fr/~pautet/Ada95/chap26.htm

Basically, three task running concurrently, display text to the
standard output stream. I've tried this one, and noticed that as the
output from each task was not atomic, output from all these tasks
ended to interlaced output on the console (notice the message each
task is displaying, made of three statement).

So I wanted to solve this, and added a protected object providing an
Put procedure which was displaying the same message, all three
statement in an atomic procedure.

It was fine and output was no more interlaced.

Later, I wanted to play a bit more and do the same with a task instead
of a protected object.

It was a task with a single entry and accept statement, Put, doing the
same, and a Terminate statement triggered when there was no more
request queued.

Later, I advised the task may terminates while some potential clients
may still be alive, or even the task may terminates before any client
had time to make any first request.

So I've decided to add a Aquire and Release entry, whose purpose was
to increase and decrease a counter, telling the output task server
that some potential clients were still alive or not. As a special
case, the initial zero value of the counter was not construed as a
terminating condition, for the same reason as explained above (some
clients may not had time to make an initial request) and it was only
interpreted as such when it was going from a non-zero value to the
zero value.

Ok, it was working fine.

Later, I wanted to make it more secure and though it would be nice to
manage these Acquire/Release invocations transparently, using a
Limited_Controller type. All clients were then required to own an
instance of this type and to pass it to the Put entry, as a proof the
client was indeed owning one. This type was named Ticket_Type.

I've created a separate package for the output task and its associated
Ticket_Type, Well, I wanted the Acquire/Release entry of the output
task to not be public any more and the Ticket_Type to be private.
Trouble : there was no way to declare the task in the public part with
a public Put entry and to give it Acquire/Release entries which would
be visible only in the private part and implementation.

The output server task only had a public Put entry, and the Acquire/
Release method were moved to a protected counter object in the
implementation. The Ticket_Type were invoking Acquire/Release on this
protected object, and the output task were requesting the counter
status on this same protected counter object.

All this story to tell to finally understand that making the output
task public, ended into more complex tricks that what I would have get
with a simple publicly declared Put procedure, implemented on top of a
task in the implementation only (the task would have had an Acquire
and Release entry, which the Ticket_Type implementation would have
accessed directly, as it would have been made private in the
implementation).

Here is my though (talking about design principle) : are tasks mostly
to be treated as things to be exposed in public part of to be treated
as implementation details ? After this experiment, I'm filling like
task are just like record components, that is, better to make these
private.

Any way, a request made to a task is blocking as long as the task is
not ready to fulfill the request (the rendezvous, which is the Ada
primitive for synchronization). So, from the client point of view, a
method implemented on top of a task is not a different thing than a
method implemented on top of a procedure.

Any experienced comments about it ?

For inquisitive peoples, here is the source (see next post) designed
with a public task, which make me think a private task is perhaps in
most of case better than a public task.

Notice there was another trouble with this source : when some
accessory stuff were removed, the output task was blocking forever,
never triggering the Terminate statement. I was circumspect about it
until I've understood this was because the select statement was not
evaluated as long as no more queued request were pending. I've solved
this in another version (not this one), using a kind of pooling with
delay..... but I do not like pooling, so I'm still working on the
subject.



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

end of thread, other threads:[~2010-02-13 11:09 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-05 20:54 Private or public task ? Hibou57 (Yannick Duchêne)
2010-02-05 20:56 ` Hibou57 (Yannick Duchêne)
2010-02-05 21:38 ` Jeffrey R. Carter
2010-02-05 21:53   ` Hibou57 (Yannick Duchêne)
2010-02-08  9:55     ` Alex R. Mosteo
2010-02-08 10:02     ` Jean-Pierre Rosen
2010-02-08 17:28     ` Maciej Sobczak
2010-02-09  8:43       ` Dmitry A. Kazakov
2010-02-09 12:07       ` Hibou57 (Yannick Duchêne)
2010-02-09 14:26         ` Jean-Pierre Rosen
2010-02-09 18:17           ` Hibou57 (Yannick Duchêne)
2010-02-10  8:17           ` Maciej Sobczak
2010-02-10  8:29             ` Hibou57 (Yannick Duchêne)
2010-02-10  8:40               ` Martin
2010-02-10 11:44                 ` Jean-Pierre Rosen
2010-02-10 12:51                   ` Martin
2010-02-10 16:17                 ` Robert A Duff
2010-02-10 11:38             ` Jean-Pierre Rosen
2010-02-13 11:09           ` Dmitry A. Kazakov
2010-02-09 15:20         ` Robert A Duff
2010-02-09 18:26           ` Hibou57 (Yannick Duchêne)
2010-02-09 14:44       ` Alex R. Mosteo
2010-02-09 23:38   ` mkasun
2010-02-09 23:51     ` Robert A Duff
2010-02-10  0:01     ` Jeffrey R. Carter
2010-02-05 21:40 ` Dmitry A. Kazakov
2010-02-05 22:09   ` Hibou57 (Yannick Duchêne)
2010-02-05 22:57     ` sjw
2010-02-06  2:20   ` Hibou57 (Yannick Duchêne)
2010-02-06  2:23     ` Hibou57 (Yannick Duchêne)
2010-02-06  3:29     ` Jeffrey R. Carter

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