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

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).