[Newbies] Simple semaphore to synchronize instances of different classes

Chris Cunnington smalltalktelevision at gmail.com
Tue Aug 14 20:07:36 UTC 2012

On 12-08-14 3:24 PM, patrick dudjalija wrote:
> Hi everybody !
> I'm developing an educative game.
> I've written a "gameEngine" class which does the logic for the general
> progression in the game : switching between instances of morph
> subclasses which implement intro screen / mini-games/levels / end
> screen etc ...
> Now, i need to synchronize the instance of the gameEngine class with
> the instances of the other classes.
> Example : once the gameEngine starts the instance of a morph subclass
> which implements a mini-game, it must sleep until the mini-game is
> finished, and then wake up and does further required switching (next
> mini-game or intro screen or end screen ...).
> i thought that a "simple" semaphore would quickly give a solution to
> the problem.
> But i get a freezed code.
> I've modelized/simplified the problem with the following workspace code.
> See also fileout of Class TestSynchro as attachment.
> TestSynchro has a step method which prints some lines to Transcript,
> then calls the method stopStepping and signal to the semaphore.
> The workspace code does a wait, before printing to Transcript 'Hello World'!
> Problem is that the code freezes , on the line code -> sem wait
> I first thought that the code freezed because in the same process. And
> added a fork to the block which creates instance of TestSynchro. But
> it does'nt help ...
> Any help will be appreciated !
> Thanks by ad2vance,
> Patrick Dudjalija
> |ts sem|
> sem:=Semaphore new.
> [ts:= TestSynchro new.
> ts semaphore:sem.
> ts openInWorld.
> ts start.] fork.
> sem wait.
> Transcript cr; show:'Hello world !';cr.
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners


I don't know much about this stuff, but using Semaphore for animations 
seems too low level. Pg. 53 of this pdf describes how step and stepTime 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/beginners/attachments/20120814/b2a5039f/attachment.htm

More information about the Beginners mailing list