|
|
Class: Monitor
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
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.
RecursionLock
Semaphore
Delay
SharedQueue
Block
instance creation
-
new
-
enter & leave
-
enter
-
enter the monitor
-
exit
-
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
initialization
-
initialize
-
queries
-
count
-
-
isFree
-
return true, if the monitor is free
(i.e. noone waits and count is zero)
-
owningProcess
-
return the monitors owner; or nil, if its free
|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.
|
|