Coming from Squeak, I'm used to its class libraryand I didn't find any
equivalent 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


_______________________________________________
help-smalltalk mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-smalltalk

Reply via email to