Possible Bug with Process terminate

Bob Arning arning at charm.net
Sat Jun 24 22:55:09 UTC 2000


On Fri, 23 Jun 2000 22:39:14 -0500 "Eric Arseneau" <eat at huv.com> wrote:
>enter: returningFlag revert: revertFlag saveForRevert: saveForRevert
>
>	| currentProcess |
>	currentProcess := Processor activeProcess.
>	[[currentProcess suspendedContext isNil] whileFalse: [
>		(Delay forMilliseconds: 200) wait].
>	Transcript cr; show: 'Hello there'] fork.
>	^super enter: returningFlag revert: revertFlag saveForRevert: saveForRevert
>
[snip]
>But it turns out that the above code does not actually work.  The reason is
>that currentProcess is nil after the active process is terminated.  Am I
>missing something here.  Is the context of the forked block removed while
>there is still a reference to it ?  What I've had to do is to make the code
>look like
>
>enter: returningFlag revert: revertFlag saveForRevert: saveForRevert
>
>	| currentProcess |
>	currentProcess := Processor activeProcess.
>	[[currentProcess isNil] whileFalse: [
>		(Delay forMilliseconds: 200) wait].
>	Transcript cr; show: 'Hello there'] fork.
>	^super enter: returningFlag revert: revertFlag saveForRevert: saveForRevert
>
>Here I actually check for the currentProcess temp variable.  In theory, I
>could put anything into that temp and this would work.
>
>Is this a bug ?  Am I missing something here ?  Is it fixed in more recent
>releases ?

Eric,

Whether it is a bug or a feature could be argued. The context variable you are watching gets cleared by the following sequence:

MethodContext>>tempAt:put:
MethodContext(ContextPart)>>unwindTo:
Process>>terminate
ProcessorScheduler>>terminateActive
Project>>spawnNewProcessAndTerminateOld:
Project>>enter:revert:saveForRevert:
[] in Project class>>returnToPreviousProject
Project(ProtoObject)>>ifNotNil:
Project class>>returnToPreviousProject

Since Squeak does not currently have full BlockClosures, parts of the system consider it acceptable to nil out the variables of contexts as they are exited. You can fix this in your case by changing

	[...] fork

to

	[...] fixTemps fork

This creates a copy of the context which will not be touched by the unwind business. You are still not out of the woods yet, because the suspendedContext does not get changed when the active process is the one being terminated. A possible solution would be to override #spawnNewProcessAndTerminateOld: in your Project and do whatever you need there just before your previous Project's process gets killed.

As a side note, please be aware that some of this is undergoing change in 2.9 and a different approach may be needed there.

Cheers,
Bob








More information about the Squeak-dev mailing list