Reflecting byneeds
Raphael Collet
raph at info.ucl.ac.be
Thu Mar 25 09:37:41 CET 2004
Andreas Rossberg wrote:
>
> OK, so I now implemented the following hack for Alice: all futures
> created are immediately made needed (by Value.makeNeeded), except for
> lazy futures. I can then distinguish them using Value.isNeeded. Since in
> the Alice model, requesting a lazy future (i.e. making it needed) turns
> it into a concurrent one, this gives precisely the right behaviour.
There is another trick. Most suspensions make a variable needed. The
suspensions that do not make a variable needed are threads suspending
with either WaitNeeded, or Value.waitQuiet. Therefore, if X is not
needed, {System.nbSusps X} returns the number of such suspensions on X.
If you know how many are of the "WaitQuiet" kind, you can deduce what
you want. Note that both the Browser and the Inspector can be
considered of the "WaitQuiet" kind here.
fun {IsByNeed X NumWaitQuiet}
{Not {IsNeeded X}} andthen {System.nbSusps X}-NumWaitQuiet > 0
end
> But I'm slightly worried about the cost. Can anybody comment on the
> overhead of this additional call to makeNeeded for every non-lazy future
> creation? Is it neglectable?
The cost of this operation is low. What it does is: deref to the
variable, change a flag inside an OzVariable object, and wake up the
suspension list. It's the same as a Wait without the suspension.
Cheers
raph
More information about the mozart-hackers
mailing list