[squeak-dev] Re: Alternate BlockContext>>forkAt: for Andreas,
was #fork and deterministic resumption of the resulting process
Paolo Bonzini
bonzini at gnu.org
Mon Mar 3 09:50:39 UTC 2008
> BlockContext>>fork
> "Create and schedule a Process running the code in the receiver."
> self newProcess resume.
> ^ nil
>
> These changes will stop forks from being used in wrong manner and
> effectively eliminate the problem of "letting fork initiator process
> to run little bit more to assign returned value anywhere".
I sort of agree (at least on the intent, of course this will break
code). However, I will point out that problematic uses are only those
who use the #fork return value in a different, already running process.
For example, this code is tricky but not racy, because the second
process isn't started until delayProcess is assigned:
delayProcess := [
(Delay forMilliseconds: msec) wait.
sema signal.
Processor activeProcess suspend ] fork ].
[[aBlock value] ensure: [delayProcess terminate. sema signal]] fork.
sema wait.
but with the sort-of-proposed change to #fork the user could be tempted
to write it like this:
[
delayProcess := Processor activeProcess.
(Delay forMilliseconds: msec) wait.
sema signal.
Processor activeProcess suspend ] fork ].
[[aBlock value] ensure: [delayProcess terminate. sema signal]] fork.
sema wait.
and the latter *is* racy.
Paolo
More information about the Squeak-dev
mailing list
|