[squeak-dev] Re: The Trunk: Kernel-mt.1009.mcz

Eliot Miranda eliot.miranda at gmail.com
Tue Apr 5 18:17:04 UTC 2016


Skipped content of type multipart/alternative-------------- next part --------------
	[
	| run priority list process1 process2 |
	run := true.
	"find an empty priority level at a priority lower than the active process"
	priority := Processor activePriority - 1.
	[(list := Processor waitingProcessesAt: priority) isEmpty] whileFalse:
		[priority := priority - 1].
	"Create two processes at that priority"
	process1 := [[run] whileTrue] forkAt: priority.
	process2 := [[run] whileTrue] forkAt: priority.
	"Check that their order in the list is the same as the order in which they were created"
	self assert: list first == process1.
	self assert: list last == process2.
	"set the flag to zero and block on a delay, allowing the processes to run to termination"
	run := false.
	(Delay forMilliseconds: 50) wait.
	"Check that they have indeed terminated"
	self assert: list isEmpty].

	[
	| run priority list process1 process2 |
	run := true.
	"find an empty priority level at a priority lower than the active process"
	priority := Processor activePriority - 1.
	[(list := Processor waitingProcessesAt: priority) isEmpty] whileFalse:
		[priority := priority - 1].
	"Create two processes at that priority"
	process1 := [[run] whileTrue] forkAt: priority.
	process2 := [[run] whileTrue] forkAt: priority.
	"Check that their order in the list is the same as the order in which they were created"
	self assert: list first == process1.
	self assert: list last == process2.
	"Now block on a delay, allowing the first one to run, spinning in its loop.
	 When the delay ends the current process will preempt process1, because process1 is at a lower priority."
	(Delay forMilliseconds: 50) wait.
	Smalltalk processPreemptionYields
		ifTrue: "If process preemption yields, process1 will get sent to the back of the run queue (which is wrong; no process explicitly yielded)"
			[self assert: list first == process2.
			 self assert: list last == process1]
		ifFalse: "If process preemption doesn't yield, the processes retain their order (yay! we indeed have cooperative scheduling within a priority)."
			[self assert: list first == process1.
			 self assert: list last == process2].
	"set the flag to zero and block on a delay, allowing the processes to run to termination"
	run := false.
	(Delay forMilliseconds: 50) wait.
	"Check that they have indeed terminated"
	self assert: list isEmpty].


	[| yielded |
	yielded := false.
	[yielded := true] fork.
	yielded].


	[| yielded |
	yielded := false.
	[yielded := true] fork.
	Processor yield.
	yielded].

	[| yielded |
	yielded := false.
	[yielded := true] fork.
	[] forkAt: Processor activePriority + 1.
	yielded].

	[| yielded |
	yielded := false.
	[yielded := true] fork.
	[] forkAt: Processor activePriority + 1.
	self assert: yielded = Smalltalk processPreemptionYields].

	[Smalltalk processPreemptionYields: true].
	[Smalltalk processPreemptionYields: false]


More information about the Squeak-dev mailing list