|
|
Class: RecursionLock
Object
|
+--RecursionLock
|
+--Dolphin::Mutex
- Package:
- stx:libbasic
- Category:
- Kernel-Processes
- Version:
- rev:
1.35
date: 2010/02/04 09:03:44
- user: stefan
- file: RecursionLock.st directory: libbasic
- module: stx stc-classLibrary: libbasic
- Author:
- Claus Gittinger
like a Semaphore for mutual exclusion, but avoids the deadlock
if a critical region is reentered by the same process again.
I.e. allows reentering the critical region IFF the current process
is the one which did the original locking.
WARNING:
for now, recursionLocks are not unlocked when an image is
restarted. You may have to recreate them to avoid a deadLock.
(this may change in the future, but recreating a recursionLock in
the #earlyRestart handling does not hurt)
Semaphore
Process
ProcessorScheduler
instance creation
-
forMutualExclusion
-
for easy exchangability with mutual-exclusion Semaphores...
-
new
-
printing & storing
-
displayString
-
return a string to display the receiver - include the
count and user-friendly name for your convenience
-
name
-
return the semaphores userFriendly name
-
name: aString
-
set the semaphores userFriendly name
private-initialization
-
initialize
-
queries
-
numberOfWaitingProcesses
-
return the number of waiting processes
-
owner
-
return the owning processes (or nil)
-
wouldBlock
-
Check if the resource represented by the receiver is
already in use by another Process.
waiting
-
critical: aBlock
-
evaluate aBlock as a critical region, but do not block,
if this lock is already held by the current process.
-
critical: aBlock ifBlocking: blockingBlock
-
like critical:, but do not block if the lock cannot be aquired.
Instead, return the value of the second argument, blockingBlock.
-
critical: aBlock timeoutMs: timeoutMs ifBlocking: blockingBlock
-
like critical:, but do not block if the lock cannot be aquired
within timeoutMs milliseconds.
Instead, return the value of blockingBlock.
example (good):
|lock|
lock := RecursionLock new.
lock critical:[
Transcript showCR:'in lock ...'.
lock critical:[
Transcript showCR:'again ...'
]
]
|
in contrast to (wrong example - deadlocks):
|lock|
lock := Semaphore forMutualExclusion.
lock critical:[
Transcript showCR:'in lock ...'.
lock critical:[
'*** never reached - deadlock because sema is already locked ***'.
' (press CTRL-c and abort in the debugger)'.
Transcript showCR:'again ...'
]
]
|
|