What is a monitor ?

R

Razvan

Hi !





Somebody asked me today what is a monitor. I said that it is some
piece of code that manages the locking mechanism and that it should
not be concerned about it because the monitor mechanism is implemented
in Java by default.
Can somebody give a more academic/corect definition ?




Regards,
Razvan
 
M

MERIGON Olivier

Hi,
This a very very academic (not very clear) definition quoted from the book
"Operating system concepts, John Wiley & sons, inc".

"A monitor is a high-level syncronization construct. It is characterized by
a set of programmer-defined operators. The representation of a monitor type
consists of declarations of variables whose values define the state of an
instance of the type, as well as the bodies of procedures or functions that
implemennt operations on that type. [...] A monitor construct ensure that
only one process at a time can be active within the monitor"

Olivier
 
C

Chris Uppal

Razvan said:
Somebody asked me today what is a monitor. I said that it is some
piece of code that manages the locking mechanism and that it should
not be concerned about it because the monitor mechanism is implemented
in Java by default.

Can somebody give a more academic/corect definition ?

According to a book I happened to have handy, the name "monitor" was invented
by Tony Hoare, and was popularised in his paper "Monitors: an operating system
structuring concept" which was published in the CACM in 1974 (it's in the ACM's
online library, but you need a subscription to read it).

Apparently the concept was then used in the Pascal family of languages.

Having wondered what "monitor" really meant myself (not being a Pascal
programmer), I went off and read the paper. Here's a summary.

A "monitor" is a programming language element used for expressing the control
of concurrency. In modern terms it is best viewed as a flavour of class with
some added elements and properties that make it well-adapted to expressing
concurrency.

A monitor is a collection of:

some data items (variables)
some procedures (methods)
some "conditions", which can be true or false.

The procedures have exclusive access to the variables and conditions (which
makes a monitor very like a modern OO object). Additionally, the
compiler/system ensures that no two procedures can be active at once (very much
like "synchronized" methods in Java). Lastly any procedure can "wait" for a
condition to become true, or it can "notify" any other processes that the state
of a condition had changed.

As you'll see, it's all very familiar. It's interesting to compare it to the
state of the art at that time. I don't think anyone (except Alan Kay, and his
associates, of course) really knew what OO was then (I don't think the term was
in anything like general use, if it had even been invented). And although
Simula had already introduced the "class" concept (Hoare mentions it in the
paper) I don't think an understanding of /objects/ (as distinct from ADTs, say)
had yet emerged. One concurrency concept that it was intended to subsume was
the "critical section", where passages of code scattered around the program
would be marked such that none of them were allowed to execute concurrently.
Compared with that (and with semaphores, etc) monitors have a much more
structured (and modern!) feel to them. BTW, Hoare ascribes the invention to
Per Hinch-Bransen.

The paper then goes on to illustrate (and prove) how monitors can be used to
solve various concurrency problems (like bounded queues, emulating semaphores,
etc), and to discuss issues like which of the waiting processes should be
scheduled next when a condition was notified. Something of a classic, that
paper...

HTH

-- chris
 
T

Thomas G. Marshall

Chris Uppal coughed up:
According to a book I happened to have handy, the name "monitor" was
invented by Tony Hoare, and was popularised in his paper "Monitors:
an operating system structuring concept"

Which IMO has always been a horrible term. To me, a "monitor" implies an
active polling view of states.
 
C

Chris Uppal

Thomas said:
Which IMO has always been a horrible term. To me, a "monitor" implies an
active polling view of states.

I agree. But it could be worse, according to Hoare Brinch-Hansen's original
name for the concept was "secretary".

Just imagine explaining Java's concurrency mechanisms: "the thing to realise is
that all Java objects are also secretaries"...

(To be fair, it may be that Brinch-Hansen's "secretary" was actually a specific
application of the idea, rather than a name for the general concept. But let's
not let that spoil the story ;-)

-- chris
 
M

Michael Saunby

The paper then goes on to illustrate (and prove) how monitors can be used to
solve various concurrency problems (like bounded queues, emulating semaphores,
etc), and to discuss issues like which of the waiting processes should be
scheduled next when a condition was notified. Something of a classic, that
paper...

Hoare's book (CSP) is now available for free download - see
http://www.usingcsp.com

Anyone with an interest in CSP (or indeed concurrency in any form) and Java
is likely to also be interested in
http://www.cs.kent.ac.uk/projects/ofa/jcsp/

Michael Saunby
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,444
Messages
2,571,709
Members
48,796
Latest member
Greg L.
Top