Process priority and portable OS threads

Bob Arning arning at charm.net
Wed Jun 2 15:16:33 UTC 1999


On Wed, 2 Jun 1999 07:06:32 -0400 "Stephen Pair" <spair at advantive.com> wrote: 
>--- process priority ---
>
>In Squeak (under Windows), when I fork a process at user background
>priority, it seems to never run (or at least it takes a very long time).  Is
>there a way to have user background priority processes to run in a more
>timely fashion.  I was creating about 100 processes to test the threaded
>call out, and everything worked great, except when I use the user level
>priority, the UI (MVC) seems to slow down.  I'd like to be able to make
>threaded call outs, leaving plenty of processing to handle the UI, but also
>having the call-out execute in a more timely manner.
>
>Can anyone shed some light on how to do this?  

Stephen,

Here is some code that may help. The basic idea is to alter the priority of processes from time to time so that each gets a chance to run. The code below did work, but I can't guarantee it to be problem-free. Hope it helps.

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