Skip to content

Commit 9d9722a

Browse files
funny-falconaclements
authored andcommitted
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 <[email protected]> Run-TryBot: Austin Clements <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent dbb13ef commit 9d9722a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/runtime/sema.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,10 @@ func (root *semaRoot) queue(addr *uint32, s *sudog, lifo bool) {
275275
// on the ticket: s.ticket <= both s.prev.ticket and s.next.ticket.
276276
// https://en.wikipedia.org/wiki/Treap
277277
// http://faculty.washington.edu/aragon/pubs/rst89.pdf
278-
s.ticket = fastrand()
278+
//
279+
// s.ticket compared with zero in couple of places, therefore set lowest bit.
280+
// It will not affect treap's quality noticeably.
281+
s.ticket = fastrand() | 1
279282
s.parent = last
280283
*pt = s
281284

0 commit comments

Comments
 (0)