[Newbies] Simple semaphore to synchronize instances of different classes

Chris Cunnington smalltalktelevision at gmail.com
Wed Aug 15 20:11:40 UTC 2012


On 12-08-15 3:12 PM, patrick dudjalija wrote:
> |ts sem|
>
> sem:=Semaphore new.
>
> [ts:= TestSynchro new.
> ts semaphore:sem.
> ts openInWorld.
> ts start.] fork.
>
> sem wait.
> Transcript cr; show:'Hello world !';cr.
Well, I can observer a few things. The first is that running this code 
in a Workspace the tem vars are unnecessary. (ie. |ts sem|). The second 
thing is that if I execute the code down to "fork" it runs fine. A blue 
square appears in the corner and it counts steps one to nine in the 
Transcript. It's only when you add "sem wait" that it freezes. I had to 
use Command+. on my Mac to unfreeze it. And I'm not convinced this is a 
bug. Remember, I don't think there is a Morph anywhere that uses 
Semaphore in #step. I have a feeling this is not a bug and that it's 
doing exactly what it's supposed to. You have created a Morph and now 
you've stopped it with #wait. I bet that's locking up the entire World, 
so it appears to freeze. That's my guess.

HTH,
Chris


More information about the Beginners mailing list