From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,385c146dd3112519,start X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!d37g2000yqa.googlegroups.com!not-for-mail From: =?ISO-8859-1?Q?Hibou57_=28Yannick_Duch=EAne=29?= Newsgroups: comp.lang.ada Subject: Private or public task ? Date: Fri, 5 Feb 2010 12:54:42 -0800 (PST) Organization: http://groups.google.com Message-ID: NNTP-Posting-Host: 86.75.149.60 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1265403282 11085 127.0.0.1 (5 Feb 2010 20:54:42 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 5 Feb 2010 20:54:42 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: d37g2000yqa.googlegroups.com; posting-host=86.75.149.60; posting-account=vrfdLAoAAAAauX_3XwyXEwXCWN3A1l8D User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; fr),gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:8916 Date: 2010-02-05T12:54:42-08:00 List-Id: 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.