Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!nntp.sei.cmu.edu!news.psc.edu!hudson.lm.com!news.math.psu.edu!chi-news.cic.net!simtel!news.sprintlink.net!howland.reston.ans.net!ix.netcom.com!netcom.com!sehyo
From: sehyo@netcom.com (Sehyo Chang)
Subject: Re: Trouble forking processes
Message-ID: <sehyoDHCHGz.GG@netcom.com>
Organization: NETCOM On-line Communication Services (408 261-4700 guest)
X-Newsreader: TIN [version 1.2 PL1]
References: <474j8d$1uf@harbinger.cc.monash.edu.au>
Date: Wed, 1 Nov 1995 03:24:34 GMT
Lines: 43
Sender: sehyo@netcom20.netcom.com

Danny H Cron (dcron@bruce.cs.monash.edu.au) wrote:
: I'm a Masters student at Monash universtiy who is using Smalltalk -
: Visual Works 2.0 to build a computer game player.  (For more details
: see www page).


: Part of creating a computer game player involves a cpu intensive search.
: I want to be able to have the computer do its "thinking" at a lower
: priority.  I have been trying to use Fork and NewProcess independantly
: to accomplish this.  They have both been successful at doing simply
: jobs in the background, but as soon as I try it with my search routine
: the system first pauses indefinately - until I hit ^C, then for some
: reason I get the search process being continually re-executed - creating
: a new process every time.

: [Aside: How do you stop a process if you don't have a "pointer" to it?]

: Note also that it works if I step though the program with the debugger.

: My system ends up playing an entire game with itself, instead of just one
: move.

: This is the lines which do the stuff:

: class := (computerPlayerClass) new: self.
: [class computerMakeControlledMove: self currentPosition] forkAt: 30.


: What am I doing wrong?

Smalltalk processes are non-preemptive light weight process.  This
means that when you fork process, it will yield until either it 
is block by semaphore or by higher priority process.

It is not easy to build true multi thread system in current smalltalk
architecture. You have to figure out how to suspend process at right
time.

Basically, if you lose process pointer, only way to suspend is to
Control-c and hunt it by doing "allInstances" or something similar
like that, which means you must track your processes carefully.

-- sehyo
