eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'Monitor':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: Monitor


Inheritance:

   Object
   |
   +--Monitor

Package:
stx:libbasic2
Category:
Kernel-Processes
Version:
rev: 1.23 date: 2017/08/09 12:13:35
user: cg
file: Monitor.st directory: libbasic2
module: stx stc-classLibrary: libbasic2
Author:
Claus Gittinger

Description:


Monitors (as used in Java) provide a functionality much like RecursionLocks, 
but are not block based.
Therefore, 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 unwind protection yourself.

Notice:
    This is an unused demo class - there is no WARRANTY.
    It is not used by the system itself.
    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  critical: aBlock
a critical section. Executes a block as a critical section, secured by the receiver.

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
(comment from inherited method)
just to ignore initialize to objects which do not need it

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 it's 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 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Thu, 18 Apr 2024 17:16:49 GMT