[squeak-dev] Alternate BlockContext>>forkAt: for Andreas, was #fork and deterministic resumption of the resulting process

Louis LaBrunda Lou at Keystone-Software.com
Sun Mar 2 17:55:12 UTC 2008


Hi Andreas,

I'm sorry to be resurrecting this thread but my mind often thinks about these
things while trying to get to sleep.  Anyway I hope my suggestions will be of
value.

I am presenting two similar suggestions.  They both accept your desire to have
the new process (or at least the block of the new process) wait to run until
after the calling process can run and save the result of the #fork message.

The first is closest to your suggestion.  Instead of a helper process it wraps
the block being forked in a block that delays running of the forked block until
there are no processes ready to run for the same priority.  I think this is
equivalent to the helper process of a lower priority waiting to run.

The second suggestion also wraps the block being forked in a block that delays
running of the forked block but does so by pushing itself to the back of the
ready to run list for its priority twice.  This should be enough to insure the
calling process has run and saved the result of the #fork message.

I'm not looking for any kind of a fight/trouble, I just thought these might be
an interesting alternative.

Lou

"Suggestion 1 from Lou"
BlockContext>>forkAt: priority 
	"Create and schedule a Process running the code in the receiver
		at the given priority. Answer the newly created process."
	| forkedProcess helperBlock |

	helperBlock := [
		[(Processor waitingProcessesAt: priority) notEmpty] whileTrue: [Processor
yield].
		self value.
	].
	forkedProcess := Process forContext: helperBlock priority: priority. 
	^forkedProcess resume.


"Suggestion 2 from Lou"
BlockContext>>forkAt: priority 
	"Create and schedule a Process running the code in the receiver
		at the given priority. Answer the newly created process."
	| forkedProcess helperBlock |

	helperBlock := [
		Processor yield.
		Processor yield.
		self value.
	].
	forkedProcess := Process forContext: helperBlock priority: priority. 
	^forkedProcess resume.



"Suggestion from Andreas"
BlockContext>>forkAt: priority
   "Create and schedule a Process running the code in the receiver
   at the given priority. Answer the newly created process."
   | forkedProcess helperProcess |

   forkedProcess := self newProcess.
   forkedProcess priority: priority.
   priority = Processor activePriority ifTrue:[
     helperProcess := [forkedProcess resume] newProcess.
     helperProcess priority: priority-1.
     helperProcess resume.
   ] ifFalse:[
     forkedProcess resume
   ].

"Original code"
BlockContext>>forkAt: priority 
	"Create and schedule a Process running the code in the receiver
		at the given priority. Answer the newly created process."

	| forkedProcess |
	forkedProcess := self newProcess.
	forkedProcess priority: priority.
	^ forkedProcess resume
-----------------------------------------------------------
Louis LaBrunda
Keystone Software Corp.
SkypeMe callto://PhotonDemon
mailto:Lou at Keystone-Software.com http://www.Keystone-Software.com




More information about the Squeak-dev mailing list