Sorting the locks is for deadlock avoidance. It ensures that all
threads try to acquire locks in the same order.
I don't have any answers for your other questions. Sorry.
I think you could make this a little more efficient but you would still
have to make sure the other branches could not be selected while
one was running. So you'd run the risk of leaving dead communications
offerings on the channel queues, and if there were many selects
on the same channel the opposite operation would have to scan
through those queues instead of being O(1). But that's probably
less likely.
So far select hasn't been a bottleneck for us.
Russ
The case selection algorithm is different from the one used in
squint. Using a random initial offset o and a random p relatively
prime to sel->ncase (gdc(p,sel->ncase)==1), the cases are visted
in the order (o+i*p)%sel->ncase for i from 0 to n-1.
This isn't always fair. See,
http://code.google.com/p/go/issues/detail?id=1425
http://codereview.appspot.com/4037043/
Eoghan
> The second thing I am interested in testing is a lazier teardown in theI think you could make this a little more efficient but you would still
> select. Essentially I would pass a hint to select for situations where I
> have
>
> while(True) {
> select {
> }
> }
have to make sure the other branches could not be selected while
one was running.
So you'd run the risk of leaving dead communications
offerings on the channel queues, and if there were many selects
on the same channel the opposite operation would have to scan
through those queues instead of being O(1). But that's probably
less likely.
So far select hasn't been a bottleneck for us.
Perhaps nothing; my point was only that the bookkeeping gets messy.
Russ
> Hi Eoghan:
>
> Thanks for the explanation. I'll go through the code again. However I am curious about
> why this algorithm is needed. Why isn't simply processing chanops in a first come first
> serve fashion fair, if one has a round-robin scheduler also? Again is the randomness an
> artifact of Newsqueak or in keeping with the non-determinism of CSP?
Non-determinism helps stop you writing bad code that depends on scheduling order.
-rob
Russ