comp.lang.ada
 help / color / mirror / Atom feed
* how to implement monitor
@ 2001-06-18  6:58 ArekB
  2001-06-18  7:52 ` Dale Stanbrough
  0 siblings, 1 reply; 3+ messages in thread
From: ArekB @ 2001-06-18  6:58 UTC (permalink / raw)


hi
I use "protected type" to implement monitor, but how to implement
conditional variables and function "signal" and "wait"
Thanks in advance
Arek






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

* Re: how to implement monitor
  2001-06-18  6:58 how to implement monitor ArekB
@ 2001-06-18  7:52 ` Dale Stanbrough
  2001-06-20 14:28   ` Mark Lundquist
  0 siblings, 1 reply; 3+ messages in thread
From: Dale Stanbrough @ 2001-06-18  7:52 UTC (permalink / raw)


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. If you do this, then you will not be following the
proper mechanism for dealing with concurrency in Ada.

Dale



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

* Re: how to implement monitor
  2001-06-18  7:52 ` Dale Stanbrough
@ 2001-06-20 14:28   ` Mark Lundquist
  0 siblings, 0 replies; 3+ messages in thread
From: Mark Lundquist @ 2001-06-20 14:28 UTC (permalink / raw)



"Dale Stanbrough" <dale@cs.rmit.edu.au> 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







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

end of thread, other threads:[~2001-06-20 14:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-18  6:58 how to implement monitor ArekB
2001-06-18  7:52 ` Dale Stanbrough
2001-06-20 14:28   ` Mark Lundquist

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