Help: #drawOn: method monopolizes processor

Bob Arning arning at charm.net
Fri Jun 18 19:32:01 UTC 1999


On Thu, 17 Jun 1999 13:02:04 "Lex Spoon" <lex at cc.gatech.edu> wrote: 
>Regarding the scheduling idea (option b), I believe you will have to explicitly do something to the thread to move it to the back of its queue.  If you interrupt thread X with a higher-priority thread H, then I'm pretty sure when H goes back to sleep, X will start back up.  Instead, H would have to do something like suspend and then resume X to force it to the back of the queue.

Lex, I think you may be a little off here. Since interrupts in Squeak are implemented as signals to a semaphore on which some process is waiting, they go through the normal suspend/resume logic. Suspending (see Interpreter>>putToSleep:) places the suspended task at the end of the linked list for its priority. Resuming takes the first. So if X and Y are processes at a low priority and H is at a high priority, then they would be run X-H-Y-H-X-H-Y, assuming that the only explicit control changes were interrupt to H which it completed processing. For a graphic example, try

http://www.charm.net/~arning/MandelBob.17Jun431pm.cs

Get 2 Mandelbrots open and they will alternate drawing simply as a result of the higher priority main event loop process periodically waking up.

>
>All in all, it  would be cool if there was an easy way to just do something like:
>
>	p becomePreemptable
>
>There could be a high-priority Squeak-wide process which periodically checks if the current process (other than itself) is marked "preemptable", and if so, preempts it.  Perhaps it would do this at each priority level....

Some code is included below to do that. It allows a process to be created with a list of prioities and time slices so that it can compete more equitably for time.

Cheers,
Bob

=============================================================
'From Squeak 2.2beta of Sept 16, 1998 on 20 January 1999 at 8:39:02 pm'!

!BlockContext methodsFor: 'scheduling' stamp: 'RAA 1/20/1999 20:38'!
toggleWith: parameterList
"Run the receiver block with alternating priorities as given by <parameterList>
this allows a process to run at high priority for best speed while dropping down
to a lower priority so that the UI does not completely die. Example:

[self doSomethingLengthy] toggleWith: {6. 600. 3. 400}
"
	| newPriority removed wait parms newProcess |
	parms _ ReadStream on: parameterList.
	newProcess _ [ 
		self value. newProcess _ nil.
	] newProcess.
	[
		newProcess priority: 4; resume.
		[newProcess isNil or: [newProcess suspendedContext isNil or:
					[newProcess isInDebugger]]] whileFalse: [
			parms atEnd ifTrue: [
				parms reset.
			].
			newPriority _ parms next.
			wait _ parms next.
			removed _ Processor remove: newProcess ifAbsent: [nil].
			removed ifNotNil: [
				newProcess offList; priority: newPriority.
				newProcess resume.
			].
			(Delay forMilliseconds: wait) wait.
		].
	] forkAt: 8.
	^newProcess! !





More information about the Squeak-dev mailing list