'From Squeak3.7 of ''4 September 2004'' [latest update: #5989] on 15 June 2009 at 11:22:20 am'!

!BlockContext methodsFor: 'scheduling' stamp: 'jmv 6/15/2009 11:21'!
fork
	"Create and schedule a Process running the code in the receiver."
	
	"jmv - Do NOT answer the new process.
	
	See http://lists.squeakfoundation.org/pipermail/squeak-dev/2008-February/124960.html
	
	Most times, this methods returns before resuming the new process (if priority of new process is less 
	or equal than current). But it might return afterwards.
	
	This means it is very dangerous to use the returned process in code that stores it in some variable 
	and checks for nil to start a new one. If this methods happens to return after the new process is forked,
	chances are the code that starts all this runs again, that variable is nil, and a second process is forked,
	perhaps breaking some shared state. This kind of bug is hard to spot and debug.
	
	Callers wanting the new process object, should call #newProcess, store the answer, and then #resume.
	
	A way to ensure this bug will not ever happen again is just to answer nil"

	self newProcess resume.
	^nil! !

!BlockContext methodsFor: 'scheduling' stamp: 'jmv 6/15/2009 11:21'!
forkAt: priority 
	"Create and schedule a Process running the code in the receiver at the given priority."
	
	"jmv - Do NOT answer the new process.
	Please see the comment at #fork"

	| forkedProcess |
	forkedProcess _ self newProcess.
	forkedProcess priority: priority.
	forkedProcess resume.
	^nil! !

!BlockContext methodsFor: 'scheduling' stamp: 'jmv 6/15/2009 11:22'!
forkAt: priority named: name
	"Create and schedule a Process running the code in the receiver at the
	given priority and having the given name."
	
	"jmv - Do NOT answer the new process.
	Please see the comment at #fork"

	| forkedProcess |
	forkedProcess := self newProcess.
	forkedProcess priority: priority.
	forkedProcess name: name.
	 forkedProcess resume.
	^nil! !

!BlockContext methodsFor: 'scheduling' stamp: 'jmv 6/15/2009 11:22'!
forkNamed: aString
	"Create and schedule a Process running the code in the receiver and
	having the given name."
	
	"jmv - Do NOT answer the new process.
	Please see the comment at #fork"

	self newProcess name: aString; resume.
	^nil! !

