9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] conditions in alts
@ 2007-12-13 23:14 Joel C. Salomon
  2007-12-14 17:37 ` Russ Cox
  0 siblings, 1 reply; 3+ messages in thread
From: Joel C. Salomon @ 2007-12-13 23:14 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Got a question about the translation of conditions in alts to
libthread, specifically the example in Russ's talk at
<http://swtch.com/~rsc/talks/threads07/#(33)>.

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [9fans] conditions in alts
  2007-12-13 23:14 [9fans] conditions in alts Joel C. Salomon
@ 2007-12-14 17:37 ` Russ Cox
  2007-12-14 18:57   ` Joel C. Salomon
  0 siblings, 1 reply; 3+ messages in thread
From: Russ Cox @ 2007-12-14 17:37 UTC (permalink / raw)
  To: 9fans

> 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [9fans] conditions in alts
  2007-12-14 17:37 ` Russ Cox
@ 2007-12-14 18:57   ` Joel C. Salomon
  0 siblings, 0 replies; 3+ messages in thread
From: Joel C. Salomon @ 2007-12-14 18:57 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Dec 14, 2007 12:37 PM, Russ Cox <rsc@swtch.com> 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-12-14 18:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-13 23:14 [9fans] conditions in alts Joel C. Salomon
2007-12-14 17:37 ` Russ Cox
2007-12-14 18:57   ` Joel C. Salomon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).