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.28 date: 2024/04/24 08:47:44
user: cg
file: Monitor.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

Description:


Monitors (as used in Java) provide a functionality much like RecursionLocks, 
but are not block based. This means that the monitor can be left at some
completely different and unrelated place from where it was acquired.

Therefore, monitors are not unwind-save 
(i.e. a return or unwind while a monitor is locked, 
can lead to a deadlock situation).

You have to care for unwind protection / cleanup yourself.
However, when waiting for a monitor, a check is made if the owning process
is still alive, and the monitor will be acquired eventually, if the owner is dead.

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.

copyright

COPYRIGHT (c) 1996 by Claus Gittinger All Rights Reserved This software is furnished under a license and may be used only in accordance with the terms of that license and with the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred.

Class protocol:

accessing
o  deadProcessPollTime
when trying to acquire a locked monitor,
check if the owning process is dead (and forgot to release)
in this cycle time

o  deadProcessPollTime: milliSecondsOrNilForDefault
when trying to acquire a locked monitor,
check if the owning process is dead (and forgot to release)
in this cycle time

instance creation
o  new
return a new unowned monitor


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 monitor's owner; or nil, if it's free


Examples:


    |mon p1 p2 p3|

    mon := Monitor new.

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

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

    p3 := [
         30 timesRepeat:[
             Delay waitForSeconds:0.1.
             mon enter.
             Transcript showCR:'p3 got it'.
             Delay waitForSeconds:0.1.
             Transcript showCR:'p3 leaves'.
             mon exit
         ]
    ] fork.
same using critical blocks
    |mon p1 p2 p3|

    mon := Monitor new.

    p1 := [
         10 timesRepeat:[
             Delay waitForSeconds:0.3.
             mon critical:[
                 Transcript showCR:'p1 got it'.
                 Delay waitForSeconds:0.3.
                 Transcript showCR:'p1 leaves'.
             ]
         ]
    ] fork.

    p2 := [
         20 timesRepeat:[
             Delay waitForSeconds:0.2.
             mon critical:[
                 Transcript showCR:'p2 got it'.
                 Delay waitForSeconds:0.2.
                 Transcript showCR:'p2 leaves'.
             ].
         ]
    ] fork.

    p3 := [
         30 timesRepeat:[
             Delay waitForSeconds:0.1.
             mon critical:[
                 Transcript showCR:'p3 got it'.
                 Delay waitForSeconds:0.1.
                 Transcript showCR:'p3 leaves'.
             ]
         ]
    ] fork.


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sat, 21 Dec 2024 18:57:37 GMT