eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'Monitor':

Home

everywhere
www.exept.de
for:
[back]

Class: Monitor


Inheritance:

   Object
   |
   +--Monitor

Package:
stx:libbasic2
Category:
Kernel-Processes
Version:
rev: 1.16 date: 2002/02/26 13:02:37
user: cg
file: Monitor.st directory: libbasic2
module: stx stc-classLibrary: libbasic2
Author:
Claus Gittinger

Description:


Monitors - functionality much like RecursionLocks, but not
block based.
Monitors are not unwind-save (i.e. a return or unwind while a
monitor is locked, will lead to a deadlock situation).
You have to care for unwinds yourself.

Notice:
    This is an experimental demo class - there is no WARRANTY.
    Smalltalkers should use Semaphores and RecursionLocks, which
    are unwind-save.


Related information:

    RecursionLock
    Semaphore
    Delay
    SharedQueue
    Block

Class protocol:

instance creation
o  new


Instance protocol:

enter & leave
o  enter
enter the monitor

o  exit
exit the monitor

o  fakeEnter: aProcess count: additionalCount
(fake-)enter the monitor, without blocking.
Raises an error, if the monitor is not free and owned by another process

initialization
o  initialize

queries
o  count

o  isFree
return true, if the monitor is free
(i.e. noone waits and count is zero)

o  owningProcess
return the monitors owner; or nil, if its free


Examples:



        |mon p1 p2 p3|

        mon := Monitor new.

        p1 := [
             10 timesRepeat:[
                 Delay waitForSeconds:0.3.
                 mon enter.
                 'p1 got it' printNL.
                 Delay waitForSeconds:0.3.
                 'p1 leaves' printNL.
                 mon exit
             ]
        ] fork.

        p2 := [
             20 timesRepeat:[
                 Delay waitForSeconds:0.2.
                 mon enter.
                 'p2 got it' printNL.
                 Delay waitForSeconds:0.2.
                 'p2 leaves' printNL.
                 mon exit
             ]
        ] fork.

        p3 := [
             30 timesRepeat:[
                 Delay waitForSeconds:0.1.
                 mon enter.
                 'p3 got it' printNL.
                 Delay waitForSeconds:0.1.
                 'p3 leaves' printNL.
                 mon exit
             ]
        ] fork.


ST/X 6.1.1; WebServer 1.620 at exept:8081; Tue, 22 May 2012 21:19:24 GMT