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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,4851adad76d89b96 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-06-20 07:28:56 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!cyclone.bc.net!newsfeed.direct.ca!look.ca!newshub2.rdc1.sfba.home.com!news.home.com!news1.sttls1.wa.home.com.POSTED!not-for-mail From: "Mark Lundquist" Newsgroups: comp.lang.ada References: <9gk8nb$20d$1@news.tpi.pl> Subject: Re: how to implement monitor X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2919.6600 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 Message-ID: Date: Wed, 20 Jun 2001 14:28:55 GMT NNTP-Posting-Host: 24.20.66.39 X-Complaints-To: abuse@home.net X-Trace: news1.sttls1.wa.home.com 993047335 24.20.66.39 (Wed, 20 Jun 2001 07:28:55 PDT) NNTP-Posting-Date: Wed, 20 Jun 2001 07:28:55 PDT Organization: Excite@Home - The Leader in Broadband http://home.com/faster Xref: archiver1.google.com comp.lang.ada:8920 Date: 2001-06-20T14:28:55+00:00 List-Id: "Dale Stanbrough" wrote in message news:dale-82F8BD.17523218062001@mec2.bigpond.net.au... > ArekB wrote: > > > hi > > I use "protected type" to implement monitor, but how to implement > > conditional variables and function "signal" and "wait" > > Thanks in advance > > You don't. Well, it *can* be done, of course... > If you do this, then you will not be following the > proper mechanism for dealing with concurrency in Ada. Quite so... and let me enlarge upon that for the benefit of the original poster. A handful of points: 1) Condition variables are not monitors! Remember that the original Hoare-style monitor concept is a language construct. CVs allow for an *approximation* of monitors in languages which lack intrinsic concurrency support. 2) Ada protected types really *are* monitors! (and other, older languages -- e.g. Mesa, Modula-2 -- had monitors, too). 3) In general, you would not want to settle for a CV/mutex solution when you have real monitors like Ada protected types. 4) To use CVs, you have to have mutexes too. Both can be implemented using Ada protected types. In terms of efficiency, the final solution is going to be inferior to a design that used protected types the way they're meant to be used. The Ada implementation is going to implement protected types the most efficient way it can; layering a CV/mutex implementation over the top of that would be a case of "abstraction inversion". I can see someone doing it as an academic exercise, but that's about all. 5) If you really want to use CVs/mutexes, it's more efficient to bind to the services provided by an OS or threads library. (The POSIX Ada binding includes the POSIX threads stuff...) So to sum it up, it can be done, but then... you are approximating monitors (as is always the case with CVs) using an abstraction that in turn is implemented in terms of real monitors. That would be the "worst of both worlds" because it loses in efficiency, safety, and expressiveness/clarity. Designing using protected types wins on all three. Have fun, Mark Lundquist