[Newbies] Simple semaphore to synchronize instances of > different classes

patrick dudjalija patrick.dudjalija at gmail.com
Thu Aug 16 16:26:52 UTC 2012


Hello Levente, Chris,

As you stated, the problem came from the code executing at UI level
(from workscript).
Forking all the script works very fine !

Thanks very much for your help !

Patrick


2012/8/16, beginners-request at lists.squeakfoundation.org
<beginners-request at lists.squeakfoundation.org>:
> Send Beginners mailing list submissions to
> 	beginners at lists.squeakfoundation.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> 	http://lists.squeakfoundation.org/mailman/listinfo/beginners
> or, via email, send a message with subject or body 'help' to
> 	beginners-request at lists.squeakfoundation.org
>
> You can reach the person managing the list at
> 	beginners-owner at lists.squeakfoundation.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Beginners digest..."
>
>
> Today's Topics:
>
>    1. Re: Simple semaphore to synchronize instances of different
>       classes (Chris Cunnington)
>    2. Re: Re: [Newbies] Simple semaphore to synchronize instances
>       of	different classes (Levente Uzonyi)
>    3. Re: Simple semaphore to synchronize instances of different
>       classes (Chris Cunningham)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Wed, 15 Aug 2012 16:11:40 -0400
> From: Chris Cunnington <smalltalktelevision at gmail.com>
> Subject: Re: [Newbies] Simple semaphore to synchronize instances of
> 	different	classes
> To: "A friendly place to get answers to even the most basic questions
> 	about	Squeak." <beginners at lists.squeakfoundation.org>
> Message-ID: <502C027C.3040900 at gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> 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
>
>
> ------------------------------
>
> Message: 2
> Date: Wed, 15 Aug 2012 23:03:27 +0200 (CEST)
> From: Levente Uzonyi <leves at elte.hu>
> Subject: Re: Re: [Newbies] Simple semaphore to synchronize instances
> 	of	different classes
> To: "A friendly place to get answers to even the most basic questions
> 	about	Squeak." <beginners at lists.squeakfoundation.org>
> Message-ID:
> 	<alpine.DEB.2.00.1208152300240.15054 at login01.caesar.elte.hu>
> Content-Type: text/plain; charset="iso-8859-1"
>
> On Wed, 15 Aug 2012, patrick dudjalija wrote:
>
>> Sorry, i've sent an unfinished mail  ...
>> Second try :
>>
>> The problem : synchronizing an instance of a class gameEngine which starts
>> instances of classes which implement transition screen / game levels.
>> Pseudo-level code :
>>
>> Game engine
>> - start introscreen- wait semaphore
>> -start level 1
>> - wait semaphore
>> - start level 2
>> -wait semaphore
>> - start finished screen
>>
>> See example of code in Squeak with semaphore in my previous mails.
>> I wonder why the code is freezing.
>
> If you evaluate something in a workspace, it will be executed by the UI
> process. If you wait for something, then the whole UI will stop responding
> while you're waiting.
> Btw, I don't think Semaphores are the thing you're looking for. Semaphores
> are for synchronizing processes, but AFAIK Morphic is a single process
> framework.
>
>
> Levente
>
>>
>> Thanks for any help.
>>
>> Patrick Dudjalija
>>
>>
>>
>> 2012/8/15 patrick dudjalija <patrick.dudjalija at gmail.com>
>>       Hello Chris !
>> Thank you for the link. Free books of Stephane Ducasse are inderdeed a
>> *MUST*.
>> http://stephane.ducasse.free.fr/FreeBooks.html
>> (BTW, everybody should consider a little donation to support him)
>>
>> I'm realizing that my question is unclear.
>> Let me have a new try in pseudocode.
>>
>> The problem : synchronizing an instance of a class gameEngine which starts
>> instances of transition screen / game levels.
>>
>> Game engine
>>
>>
>>
>>
>>
>> 2012/8/15 <beginners-request at lists.squeakfoundation.org>
>>       Send Beginners mailing list submissions to
>>               beginners at lists.squeakfoundation.org
>>
>>       To subscribe or unsubscribe via the World Wide Web, visit
>>
>> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>>       or, via email, send a message with subject or body 'help' to
>>               beginners-request at lists.squeakfoundation.org
>>
>>       You can reach the person managing the list at
>>               beginners-owner at lists.squeakfoundation.org
>>
>>       When replying, please edit your Subject line so it is more specific
>>       than "Re: Contents of Beginners digest..."
>>
>>
>>       Today's Topics:
>>
>>          1. Simple semaphore to synchronize instances of different
>>             classes (patrick dudjalija)
>>          2. Re: Simple semaphore to synchronize instances of different
>>             classes (Chris Cunnington)
>>
>>
>>
>> ----------------------------------------------------------------------
>>
>>       Message: 1
>>       Date: Tue, 14 Aug 2012 21:24:06 +0200
>>       From: patrick dudjalija <patrick.dudjalija at gmail.com>
>>       Subject: [Newbies] Simple semaphore to synchronize instances of
>>               different       classes
>>       To: beginners <beginners at lists.squeakfoundation.org>
>>       Message-ID:
>>
>> <CAEMqm6GttreSY5i+SA=Hg1=C8sAszQOu63miV_R5cfAW5a77Sw at mail.gmail.com>
>>       Content-Type: text/plain; charset="iso-8859-1"
>>
>>       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 advance,
>>
>>       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.
>> -------------- next part --------------
>> A non-text attachment was scrubbed...
>> Name: TestSynchro.st
>> Type: application/octet-stream
>> Size: 2201 bytes
>> Desc: not available
>> Url :
>> http://lists.squeakfoundation.org/pipermail/beginners/attachments/20120814/8d30cdd2/TestSynchro-0001.obj
>>
>> ------------------------------
>>
>> Message: 2
>> Date: Tue, 14 Aug 2012 16:07:36 -0400
>> From: Chris Cunnington <smalltalktelevision at gmail.com>
>> Subject: Re: [Newbies] Simple semaphore to synchronize instances of
>>         different       classes
>> To: beginners at lists.squeakfoundation.org
>> Message-ID: <502AB008.3030104 at gmail.com>
>> Content-Type: text/plain; charset="iso-8859-1"
>>
>> 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
>>
>> http://stephane.ducasse.free.fr/FreeBooks/GuzdialBookDrafts/BuildUI-ch5.pdf
>>
>> 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
>> work.
>>
>> HTH,
>> Chris
>>
>>
>>
>> -------------- next part --------------
>> An HTML attachment was scrubbed...
>> URL:
>> http://lists.squeakfoundation.org/pipermail/beginners/attachments/20120814/b2a5039f/attachment-0001.htm
>>
>> ------------------------------
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners at lists.squeakfoundation.org
>> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>>
>>
>> End of Beginners Digest, Vol 76, Issue 5
>> ****************************************
>>
>>
>>
>>
>>
>
> ------------------------------
>
> Message: 3
> Date: Wed, 15 Aug 2012 16:42:33 -0700
> From: Chris Cunningham <cunningham.cb at gmail.com>
> Subject: Re: [Newbies] Simple semaphore to synchronize instances of
> 	different	classes
> To: "A friendly place to get answers to even the most basic questions
> 	about	Squeak." <beginners at lists.squeakfoundation.org>
> Message-ID:
> 	<CAPp9i4mHgxFSLsWUvbJZDZ1Q4FRWNLp2fXyXZTPNkM1CuZvfHQ at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> On Wed, Aug 15, 2012 at 1:11 PM, Chris Cunnington
> <smalltalktelevision at gmail.com> wrote:
>> 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
>
> So, if you'd still like to do it this way, if you place your entire
> script from the workspace into a [] fork, it should then work (since
> it will no longer block the UI process).
>
>
> ------------------------------
>
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
>
> End of Beginners Digest, Vol 76, Issue 7
> ****************************************
>


More information about the Beginners mailing list