Process status
Tim Olson
tim at jumpnet.com
Sun Jul 12 13:34:16 UTC 1998
>That won't work, because after the loop pid is 3 and all processes
>return that value. So how do I create a variable, that is local to a
>block? Something like [:pid| blockTemp | blockTemp := pid ] won't work
>either.
Squeak doesn't have true block temporary variables (not yet, anyway!);
they are shared at the method level. Instead of having the forked block
perform the thread function, you should have the block invoke a method,
with the shared queue and the pid as parameters. Also, you should have
your outer-loop perform a "Processor yield" at the end of each iteration
to give the forked process a chance to grab the current (shared) pid
value.
| sq |
sq := SharedQueue new.
sq nextPut: 'Nasi'; nextPut: 'Goreng'; nextPut: 'Chop'; nextPut: 'Suey'.
1 to: 2 do: [:pid |
[TestBlock new run: sq withPID: pid] fork. Processor yield].
where TestBlock>>run:withPID: looks like:
run: q withPID: p
[q isEmpty] whileFalse:
[Transcript show: p printString , ': ', q next; cr.
Processor yield].
Transcript show: p printString, ' done.'; cr.
-- tim
More information about the Squeak-dev
mailing list
|