eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'RecursionLock':

Home

everywhere
www.exept.de
for:
[back]

Class: RecursionLock


Inheritance:

   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

Description:


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)


Related information:

    Semaphore
    Process
    ProcessorScheduler

Class protocol:

instance creation
o  forMutualExclusion
for easy exchangability with mutual-exclusion Semaphores...

o  new


Instance protocol:

printing & storing
o  displayString
return a string to display the receiver - include the
count and user-friendly name for your convenience

o  name
return the semaphores userFriendly name

o  name: aString
set the semaphores userFriendly name

private-initialization
o  initialize

queries
o  numberOfWaitingProcesses
return the number of waiting processes

o  owner
return the owning processes (or nil)

o  wouldBlock
Check if the resource represented by the receiver is
already in use by another Process.

waiting
o  critical: aBlock
evaluate aBlock as a critical region, but do not block,
if this lock is already held by the current process.

o  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.

o  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.


Examples:


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 ...'
      ]
  ]


ST/X 6.1.1; WebServer 1.620 at exept:8081; Wed, 23 May 2012 20:55:34 GMT