From: Sokolov Yura Date: Wed, 4 Oct 2017 11:35:33 +0000 (+0300) Subject: runtime: fix using fastrand in sema.go X-Git-Tag: go1.10beta1~877 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=9d9722a2e16fa3f31dc336f4b12ef4d45e770e66;p=gostls13.git runtime: fix using fastrand in sema.go Before CL 62530 fastrand always returned non-zero value, and one condition in sema.go depends on this behavior. fastrand is used to generate random weight for treap of sudog, and it is checked against zero to verify sudog were inserted into treap or wait queue. Since its precision is not very important for correctness, lets just always set its lowest bit in this place. Updates #22047 Updates #21806 Change-Id: Iba0b56d81054e6ef9c49ffd293fc5d92a6a31e9b Reviewed-on: https://go-review.googlesource.com/68050 Reviewed-by: Austin Clements Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot --- diff --git a/src/runtime/sema.go b/src/runtime/sema.go index 8715e07d7a..d5ea14d46d 100644 --- a/src/runtime/sema.go +++ b/src/runtime/sema.go @@ -275,7 +275,10 @@ func (root *semaRoot) queue(addr *uint32, s *sudog, lifo bool) { // on the ticket: s.ticket <= both s.prev.ticket and s.next.ticket. // https://en.wikipedia.org/wiki/Treap // http://faculty.washington.edu/aragon/pubs/rst89.pdf - s.ticket = fastrand() + // + // s.ticket compared with zero in couple of places, therefore set lowest bit. + // It will not affect treap's quality noticeably. + s.ticket = fastrand() | 1 s.parent = last *pt = s