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@lists.squeakfoundation.org
Send Beginners mailing list submissions to beginners@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@lists.squeakfoundation.org
You can reach the person managing the list at beginners-owner@lists.squeakfoundation.org
When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..."
Today's Topics:
- Simple semaphore to synchronize instances of different classes (patrick dudjalija)
- 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@gmail.com Subject: [Newbies] Simple semaphore to synchronize instances of different classes To: beginners beginners@lists.squeakfoundation.org Message-ID: <CAEMqm6GttreSY5i+SA=Hg1= C8sAszQOu63miV_R5cfAW5a77Sw@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.
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.
Thanks for any help.
Patrick Dudjalija
2012/8/15 patrick dudjalija patrick.dudjalija@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@lists.squeakfoundation.org
Send Beginners mailing list submissions to beginners@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@lists.squeakfoundation.org
You can reach the person managing the list at beginners-owner@lists.squeakfoundation.org
When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..."
Today's Topics:
- Simple semaphore to synchronize instances of different classes (patrick dudjalija)
- 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@gmail.com Subject: [Newbies] Simple semaphore to synchronize instances of different classes To: beginners beginners@lists.squeakfoundation.org Message-ID: <CAEMqm6GttreSY5i+SA=Hg1= C8sAszQOu63miV_R5cfAW5a77Sw@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.
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
On Wed, Aug 15, 2012 at 1:11 PM, Chris Cunnington smalltalktelevision@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).
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@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@lists.squeakfoundation.org Send Beginners mailing list submissions to beginners@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@lists.squeakfoundation.org You can reach the person managing the list at beginners-owner@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@gmail.com> Subject: [Newbies] Simple semaphore to synchronize instances of different classes To: beginners <beginners@lists.squeakfoundation.org> Message-ID: <CAEMqm6GttreSY5i+SA=Hg1=C8sAszQOu63miV_R5cfAW5a77Sw@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.
beginners@lists.squeakfoundation.org