(no subject)

Colin Putney cputney at wiresong.ca
Sat Nov 27 23:40:27 UTC 2004


On Nov 27, 2004, at 6:33 PM, Ryan Zerby 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?

In Smalltalk, threads are called processes. See the class Process for 
the messages you can send to one. To fork off a Process, just send 
#fork to a block containing the code you want to run in the process. As 
a simple example, assume aiProcess is an instance variable of some 
object:

startAIProcess
	aiProcess := [AI new run] fork

stopAIProcess
	aiProcess terminate




More information about the Squeak-dev mailing list