Point me to the docs for threads

Brian Tabone brian.tabone at gmail.com
Sun Nov 28 05:27:06 UTC 2004


Read up on fork and forkAt:, which are messages that Block objects
respond too. Also read up in the system class on ProcessorScheduler
and the scheduler priorities.

Here's a trivial piece of code I wrote to play around with forked
processes and semaphores:

| ourSemaphore  |

ourSemaphore := Semaphore new.
[ourSemaphore wait.
Transcript show:'I waited'; cr.
ourSemaphore signal.]fork.

[Transcript show:'I signaled'; cr.
ourSemaphore signal.
ourSemaphore wait.
Transcript show:'Then I wrote again';  cr]fork.

You'll probably want to put your AI or a call to your AI class in a
block, then forkAt:Processor userBackgroundPriority.

For example 
...
[doSomeAiThinking] forkAt: (Processor userBackgroundPriority).
...

This will fork off your AI work into a background process. You could
use some Semaphores to start and stop it as need be.

Hope that helps,
Brian Tabone

On Sat, 27 Nov 2004 15:33:00 -0800, Ryan Zerby <tahognome at gmail.com> wrote:
> For my game, I'd like the AI to run in the background for X number of
> seconds. I don't want it to lock up the UI while it's thinking.  In
> other languages, I've done this by firing off the AI
> as a thread, then creating another clock that sent a "stop" message to
> the AI after X seconds.
> 
> I see implementing the clock as a Delay class.. but need a bit help
> figuring out the details of forking off the original AI process.
> 
> Can someone point me to docs or examples?
> 
>



More information about the Squeak-dev mailing list