Hi,
Coming from Squeak, I'm used to its class libraryand I didn't find any equivalent of the UUID and Monitor classes. Did I miss them? Cheers! Nico _______________________________________________ help-smalltalk mailing list [hidden email] http://lists.gnu.org/mailman/listinfo/help-smalltalk signature.asc (204 bytes) Download Attachment |
> 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 [hidden email] http://lists.gnu.org/mailman/listinfo/help-smalltalk |
Thanks Paolo, I'll have a look at those classes.
One other question, is there something like the MessageTally class in Squeak?. This class is especially useful when used together with Seaside (in WAProfiler). Cheers! Nico Le mercredi 17 juin 2009 à 08:32 +0200, Paolo Bonzini a écrit : > > 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 [hidden email] http://lists.gnu.org/mailman/listinfo/help-smalltalk signature.asc (204 bytes) Download Attachment |
Nicolas Petton wrote:
> Thanks Paolo, I'll have a look at those classes. > > One other question, is there something like the MessageTally class in > Squeak?. I usually use the code in unsupported/Profile.st: Bag subclass: IdentityBag [ dictionaryClass [ ^IdentityDictionary ] ] BlockClosure extend [ profile [ | s profProcess workProcess results | s := Semaphore new. results := IdentityBag new. workProcess := self newProcess. profProcess := [ workProcess resume. [ (Delay forMilliseconds: 5) wait. workProcess isTerminated ] whileFalse: [ results add: workProcess suspendedContext method. ]. s signal ] forkAt: Processor highIOPriority. s wait. ^results sortedByCount ] ] [10000 factorial] profile do: [ :each|each printNl ] _______________________________________________ help-smalltalk mailing list [hidden email] http://lists.gnu.org/mailman/listinfo/help-smalltalk |
It works fine, thanks :)
Le mercredi 17 juin 2009 à 15:29 +0200, Paolo Bonzini a écrit : > Nicolas Petton wrote: > > Thanks Paolo, I'll have a look at those classes. > > > > One other question, is there something like the MessageTally class in > > Squeak?. > > I usually use the code in unsupported/Profile.st: > > Bag subclass: IdentityBag [ > dictionaryClass [ ^IdentityDictionary ] > ] > > BlockClosure extend [ > > profile [ > | s profProcess workProcess results | > s := Semaphore new. > results := IdentityBag new. > workProcess := self newProcess. > profProcess := [ > workProcess resume. > [ > (Delay forMilliseconds: 5) wait. > workProcess isTerminated > ] whileFalse: [ > results add: workProcess suspendedContext method. > ]. > s signal > ] forkAt: Processor highIOPriority. > s wait. > ^results sortedByCount > ] ] > > [10000 factorial] profile do: [ :each|each printNl ] _______________________________________________ help-smalltalk mailing list [hidden email] http://lists.gnu.org/mailman/listinfo/help-smalltalk signature.asc (204 bytes) Download Attachment |
Free forum by Nabble | Edit this page |