|
From: | Paolo Bonzini |
Subject: | Re: [Help-smalltalk] UUID and Monitor Squeak classes equivalent in gst? |
Date: | Wed, 17 Jun 2009 08:32:36 +0200 |
User-agent: | Thunderbird 2.0.0.17 (X11/20081009) |
Coming from Squeak, I'm used to its class libraryand I didn't find anyequivalent of the UUID and Monitor classes.
UUID is implemented as part of the platform layer of Magritte, though with the time-based UUIDv1 algorithm if I remember correctly.
I think if you're using only Monitor>>#critical: the equivalent is RecursionLock. For more complicated stuff, Semaphore has additional methods #notify (like #signal, but never increment the count above 0) and #notifyAll (to wake up all processes). For example, this example of Squeak monitors
BoundedCounter>>dec monitor critical: [ monitor waitUntil: [value > self lowerBound]. value = self upperBound ifTrue: [monitor signalAll]. value _ value - 1]. BoundedCounter>>inc monitor critical: [ monitor waitUntil: [value < self upperBound]. value = self lowerBound ifTrue: [monitor signalAll]. value _ value + 1]. could be written like this: BoundedCounter>>initialize mutex := RecursionLock new. condition := Semaphore new. BoundedCounter>>dec | oldValue | [mutex critical: [ value > self lowerBound ifTrue: [ value = self upperBound ifTrue: [condition notifyAll]. value _ value - 1. ^self]]. condition wait] repeat BoundedCounter>>inc [mutex critical: [ value < self upperBound ifTrue: [ value = self lowerBound ifTrue: [condition notifyAll]. value _ value + 1. ^self]]. condition wait] repeat(I'm pretty sure that the Monitor class in Squeak has race conditions that may leave the monitor in an unstable state if the involved processes are terminated; see the complications in Semaphore>>#critical:. That's why I never got to implementing it in GNU Smalltalk).
Paolo
[Prev in Thread] | Current Thread | [Next in Thread] |