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.1 required=5.0 tests=BAYES_00, PP_MIME_FAKE_ASCII_TEXT autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!newsfeed.fsmpi.rwth-aachen.de!reality.xs3.de!news.jacob-sparre.dk!loke.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: can someone help me with this code (explanation) Date: Wed, 8 Oct 2014 21:45:01 -0500 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: References: <6e1f86e6-c17a-428e-bb19-460c5ba26c8a@googlegroups.com> <1ec7272d-de7f-43dd-be30-009c437011de@googlegroups.com> NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: loke.gir.dk 1412822702 21835 69.95.181.76 (9 Oct 2014 02:45:02 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Thu, 9 Oct 2014 02:45:02 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 Xref: news.eternal-september.org comp.lang.ada:22266 Date: 2014-10-08T21:45:01-05:00 List-Id: "Niklas Holsti" wrote in message news:c8ljhpFaqrfU4@mid.individual.net... > On 14-09-26 10:58 , J-P. Rosen wrote: >> Le 26/09/2014 09:04, Björn Lundin a écrit : >>> Or by using a protected object as a semaphore >>> >> But why? It's so simpler with a task: >> >> task Printer is >> entry Print (Mess : String); >> end Printer; > > The semaphore solution lets one group related output lines together; the > task+entry (in the above form) can interleave output lines from > different tasks, perhaps making output harder to read. Whether this > matters depends on what one needs. Right. Note that the semaphore ought to be wrapped in a Limited_Controlled object so that it gets unlocked if the scope is exited by an exception. That's especially important for protecting I/O, since I/O routines have a tendency to propagate an exception because of full disks, permissions errors, etc. Without such protection, an exception would leave the semaphore locked and you'll end up with deadlock as no task can do any I/O. (The task version probably ought to be protected from exceptions as well, I'll leave that as an exercise for the reader.) Randy.