[squeak-dev] Another bug in Process>>#terminate in unwinding contexts ?

Jaromir Matas m at jaromir.net
Wed Mar 31 17:58:01 UTC 2021


Unfortunately there's one more bug in #terminate:

The existing code fails to execute unwind blocks after completing the
innermost unwind block. Examine the following example nesting two unwind
blocks halfway through execution and one outer unwind block not started yet:

| p |
p := [
	[
		[ ] ensure: ["x2"
			[ ] ensure: ["x1"
				Processor activeProcess suspend. 
				Transcript show: 'x1']. 
			Transcript show: 'x2']
	] ensure: ["x3"
		Transcript show: 'x3']
] fork.
Processor yield.
p terminate

---> x1 (only!)

Process p is suspended halfway through an unwind block x1 and is terminated
- you'd expect #terminate to finish the unfinished unwind blocks x1 and x2
and execute an outer unwind block x3. But the result is only x1 is completed
and both x2 and x3 are ignored!

The reason x3 is ignored is that #runUntilErrorOrReturnFrom: resets
suspendedContext sender to nil so the rest of the code is doing nothing
useful. The fix is to update suspendedContext after
#runUntilErrorOrReturnFrom is returned from.

Process >> terminate
		"..."
		ctxt := suspendedContext.
		[ctxt := ctxt findNextUnwindContextUpTo: nil.
		 ctxt ~~ nil] whileTrue: 
			[(ctxt tempAt:2) ifNotNil: [outerMost := ctxt]].
		outerMost ifNotNil: ["This is the bottom-most unwind context currently
under evaluation;
			now let's find the currently context executing its argument block
(tempAt: 1)"
			(suspendedContext findContextSuchThat: [:c | c closure == (outerMost
tempAt: 1)]) ifNotNil:
				[:inner | 
					suspendedContext runUntilErrorOrReturnFrom: inner.
					"update suspendedContext"
					suspendedContext := outerMost]].
		"..."

Now the test example returns 'x1 x2 x3' as expected.

Updated changeset enclosed:  Process-terminate_modify_outerMost_v2.st
<http://forum.world.st/file/t372955/Process-terminate_modify_outerMost_v2.st>  

Thanks for your comments.



-----
^[^ Jaromir
--
Sent from: http://forum.world.st/Squeak-Dev-f45488.html


More information about the Squeak-dev mailing list