[squeak-dev] Process >> #priority bug

mail at jaromir.net mail at jaromir.net
Tue Dec 7 21:43:48 UTC 2021


Hi all,

Summary: In http://forum.world.st/The-Inbox-Kernel-jar-1368-mcz-td5126894.html it has been discussed and agreed Process >> #priority is not working properly when downgrading the active process's priority: neither Process Scheduler nor #yield check if there are higher priority processes waiting and let the freshly downgraded active process continue, ignoring any waiting higher priority processes until the next suspension point appears (which may take a while). This behavior is a bug and causes the following simple tests fail:

	| val oldPriority |
	oldPriority := Processor activePriority.
	Processor activeProcess priority: oldPriority + 2.
	[ val := true ] forkAt: oldPriority + 1.
	Processor activeProcess priority: oldPriority.
	self assert: val = true

and

	| val oldPriority |
	oldPriority := Processor activePriority.
	[
		[ val := true ] forkAt: oldPriority + 1.
	] valueUnpreemptively.
	self assert: val = true

I suggested a rough patch that would introduce a new suspension point allowing Process Scheduler to get the job done right (Kernel-jar.1368):

priority: anInteger 
	"Set the receiver's priority to anInteger."
	(anInteger >= Processor lowestPriority and:[anInteger <= Processor highestPriority])
		ifTrue: [priority := anInteger.
------>			self isActiveProcess ifTrue: [[] forkAt: Processor highestPriority]]
		ifFalse: [self error: 'Invalid priority: ', anInteger printString]

Indeed, the best solution would be to replace this crude and slow patch with a primitive - this has been discussed and agreed as well ("fixing" #yield wouldn't help much because it would introduce the potentially unwanted side-effect of yielding).


I wonder: would it make sense to merge this interim patch or is it better to wait and fix it properly with a primitive (which is unfortunately way beyond my skills)? Or maybe at least add a comment to #priority descibing the bug? Or even add the following test as an "expected failure" as a reminder? (KernelTests-jar.393)


testPriority
	"test whether #priority: preempts active process to allow higher priority processes run"

	| val oldPriority |
	oldPriority := Processor activePriority.
	Processor activeProcess priority: oldPriority + 2.
	[ val := false ] forkAt: oldPriority + 1.
	[ val := true ] forkAt: oldPriority.
	Processor activeProcess priority: oldPriority.
	self assert: val = Smalltalk processPreemptionYields.

Thanks,
best,


~~~
^[^    Jaromir

Sent from Squeak Inbox Talk


More information about the Squeak-dev mailing list