date: 2017/08/09 12:13:35
- user: cg
- file: Monitor.st directory: libbasic2
- module: stx stc-classLibrary: libbasic2
- Claus Gittinger
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.
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
enter & leave
a critical section. Executes a block as a critical section, secured by the receiver.
enter the monitor
exit the monitor
fakeEnter: aProcess count: additionalCount
(fake-)enter the monitor, without blocking.
Raises an error, if the monitor is not free and owned by another process
(comment from inherited method)
just to ignore initialize to objects which do not need it
return true, if the monitor is free
(i.e. noone waits and count is zero)
return the monitors owner; or nil, if it's free
|mon p1 p2 p3|
mon := Monitor new.
p1 := [
'p1 got it' printNL.
'p1 leaves' printNL.
p2 := [
'p2 got it' printNL.
'p2 leaves' printNL.
p3 := [
'p3 got it' printNL.
'p3 leaves' printNL.