[9fans] conditions in alts - Plan9
This is a discussion on [9fans] conditions in alts - Plan9 ; Got a question about the translation of conditions in alts to
libthread, specifically the example in Russ's talk at
.
The syntax,
alt {
x =
print("received %d from c1\n", x);
cond && c2
print("sent %d to c2\n", y);
}
...
-
[9fans] conditions in alts
Got a question about the translation of conditions in alts to
libthread, specifically the example in Russ's talk at
.
The syntax,
alt {
x = <-c1:
print("received %d from c1\n", x);
cond && c2 <-= y:
print("sent %d to c2\n", y);
}
implies that the condition is re-evaluated. I.e., if c1 isn't ready
and c2 is but cond is false, then the alt blocks until either c1
becomes ready or the condition turn true. The libthread translation,
alts[1] = (Alt){c2, &y, cond ? CHANSND : CHANNOP};
alts[2] = (Alt){nil, nil, CHANEND};
switch(alt(alts)){
…
on the other hand, makes it pretty clear that the condition is
evaluated only once. Is that a limitation of the implementation of
libthread, or are those the intended semantics?
--Joel
-
Re: [9fans] conditions in alts
> The syntax,
> alt {
> x = <-c1:
> print("received %d from c1\n", x);
> cond && c2 <-= y:
> print("sent %d to c2\n", y);
> }
> implies that the condition is re-evaluated.
Doesn't imply that to me.
> The libthread translation,
> alts[1] = (Alt){c2, &y, cond ? CHANSND : CHANNOP};
> alts[2] = (Alt){nil, nil, CHANEND};
> switch(alt(alts)){
> …
> on the other hand, makes it pretty clear that the condition is
> evaluated only once. Is that a limitation of the implementation of
> libthread, or are those the intended semantics?
When I wrote the syntax at the top, I meant the
semantics to be what the libthread translation says.
If you look at how I used it the one time it was in the
slides, the condition couldn't change while the alt was
blocked -- it involved only local variables. In fact if
you have arranged things so that there are no shared
mutable variables then the condition can't possibly
change during the alt. So this is reasonable.
Russ
-
Re: [9fans] conditions in alts
On Dec 14, 2007 12:37 PM, Russ Cox wrote:
> If you look at how I used it the one time it was in the
> slides, the condition couldn't change while the alt was
> blocked -- it involved only local variables. In fact if
> you have arranged things so that there are no shared
> mutable variables then the condition can't possibly
> change during the alt. So this is reasonable.
OK, that makes sense now. Thanks.
--Joel