Squeak does not do pre-emptive multitasking.

Michael van der Gulik squeakml at gulik.co.nz
Sat Jun 10 23:42:24 UTC 2006


Hi all.

I had some weird behaviour when doing some multi-threaded coding. I 
wrote a test (attached) to test the way the VM schedules processes.

I am not impressed. These were the results of running it several times:

t := TestingScheduler new.
t numProcesses: 10.

#(12127412 12126870 12127386 12127374 12127362 0 0 0 0 0)
#(21112051 21112060 21111787 0 0 0 0 0 0 0)
#(25767847 25768314 25767577 0 0 0 0 0 0 0)
#(31379008 31378493 0 0 0 0 0 0 0 0)

What you are looking at is the result of 10 threads battling it out to 
increment their respective array elements.

Either:

- My code is borked, which is entirely possible,
- The ProcessScheduler is buggy, or
- Squeak is meant to work like this.

Which of those is true?

I'm running Squeak 3.8 #6665 on what I believe is the latest Linux VM.

Michael.
-------------- next part --------------
'From Squeak3.8 of ''5 May 2005'' [latest update: #6665] on 11 June 2006 at 11:26:35 am'!
Object subclass: #TestingScheduler
	instanceVariableNames: 'processes continue counts'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'playing'!

!TestingScheduler methodsFor: 'as yet unclassified' stamp: 'mvdg 6/11/2006 11:26'!
loop: element
	[[ continue ] whileTrue: [ 
		counts at: element put: ((counts at: element) + 1).
	] ] forkAt: 10.
	! !

!TestingScheduler methodsFor: 'as yet unclassified' stamp: 'mvdg 6/8/2006 22:05'!
numProcesses: num
	continue := true.
	counts := Array new: num.
	1 to: num do: [ :each |
		counts at: each put: 0.
		self loop: each.
	].
	counts inspect.
	(Delay forSeconds: 15) wait.
	continue := false.! !

!TestingScheduler methodsFor: 'as yet unclassified' stamp: 'mvdg 6/8/2006 21:36'!
stop
	continue := false.! !


More information about the Squeak-dev mailing list