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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,9b794838d82ee7c3 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder.news-service.com!feeder.news-service.com!newsfeed.freenet.de!bolzen.all.de!newsfeed.ision.net!newsfeed2.easynews.net!ision!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Task vs Protected Type Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: Date: Fri, 30 May 2008 16:33:09 +0200 Message-ID: <1q9sdmclm9qew.15yh93h5qg3l.dlg@40tude.net> NNTP-Posting-Date: 30 May 2008 16:33:09 CEST NNTP-Posting-Host: 85b88958.newsspool1.arcor-online.net X-Trace: DXC=9l8>bM@=O2C6PJ?[X6JIXEic==]BZ:afN4Fo<]lROoRA<`=YMgDjhgB^i`d^>^DLEA[6LHn;2LCVN7enW;^6ZC`DIXm65S@:3>OQ<^AbOH;BDA X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:479 Date: 2008-05-30T16:33:09+02:00 List-Id: On Fri, 30 May 2008 14:12:49 +0000, in comp.lang.ada you wrote: > I would like to understand a sentence of the wikibook. [...] > The first one has the advantage to force the user to Initialize the task > because of the first entry, but there is no such mechanism in the > protected type. Of course there is many. For example: protected type Semaphore_Protected_Type (N : Natural) is ... private Count : Natural := N; end Semaphore_Protected_Type; > So in the wikibook, there is this sentence: > "Alternatively, semaphore functionality can be provided by a protected > object, with major efficiency gains." > > This is between the two codes, letting the reader (me at least) > understand protected type is a better approach, but I can't understand why. It is sometimes better, because seizing a semaphore implemented by a protected object does not require context switching, as it can accomplished on the caller's context. A rendezvous with the semaphore's monitor task would usually require switching the context twice. > For example, you have a web application and want to develop an object > pool. You could use one of both example, since it's the same purpose > with some GetObject and ReleaseObject enties/procedure in a task or in a > protected. But which one is the better approach? Neither. It is a bad idea to use tasks for implementation of low-level synchronization primitives (like semaphores). Your web application would probably do much more things than just locking. Instead of Wait, you would likely have something like Service (Object), which is more like a transaction. Because the time required for handling higher level requests is sufficiently greater than mere switching contexts, the difference might become negligible. At the same time protected objects tend to be too low-level. Further, protected actions shall be very short. This requirement forces a very heavy design, when you have to do some prologue as a protected action, continue work outside it, and complete it again as a protected action again. Such things, and semaphore is a typical example of, are exposed to various nasty problems. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de