choleraehyq
不知道为啥要在汇编代码前面加 `// build !race` 去了之后写了个俩消费者俩生产者的 demo,然后 `go run -race demo.go` 跑了一下就 race 了。 看到你给 go 提的 xor 的 issue 追过来的,想顺便问一下你提到的 intel 汇编的那个指令编程优化手册是在哪找到的,能否发个链接? demo.go: ``` package main import ( "sync" "github.com/templexxx/fqueue" ) func main() { q, err := fqueue.New(16) if err != nil { panic(err) } var w sync.WaitGroup w.Add(4) go func() { defer w.Done() for i := 0; i < 10000; i++ { q.Push(i) } }() go func() { defer w.Done() for i := 10000; i < 20000; i++ { q.Push(i) } }() go func() { defer w.Done() for i := 0; i < 10000; i++ { q.Get() } }() go func() { defer w.Done() for i := 10000; i < 20000; i++ { q.Get() } }() w.Wait() } ``` ``` ================== WARNING: DATA RACE Read at 0x00c42007c028 by goroutine 7: github.com/templexxx/fqueue.(*queue).Get() /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:111 +0x15e main.main.func3() /home/cholerae/test/gotest/testfqueue.go:30 +0x6b Previous write at 0x00c42007c028 by goroutine 5: github.com/templexxx/fqueue.(*queue).Push() /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:77 +0x1b8 main.main.func1() /home/cholerae/test/gotest/testfqueue.go:18 +0x9e Goroutine 7 (running) created at: main.main() /home/cholerae/test/gotest/testfqueue.go:27 +0x1c0 Goroutine 5 (running) created at: main.main() /home/cholerae/test/gotest/testfqueue.go:15 +0x168 ================== ================== WARNING: DATA RACE Read at 0x00c42007c040 by goroutine 8: github.com/templexxx/fqueue.(*queue).Get() /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:111 +0x15e main.main.func4() /home/cholerae/test/gotest/testfqueue.go:36 +0x6e Previous write at 0x00c42007c040 by goroutine 5: github.com/templexxx/fqueue.(*queue).Push() /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:77 +0x1b8 main.main.func1() /home/cholerae/test/gotest/testfqueue.go:18 +0x9e Goroutine 8 (running) created at: main.main() /home/cholerae/test/gotest/testfqueue.go:33 +0x1ec Goroutine 5 (running) created at: main.main() /home/cholerae/test/gotest/testfqueue.go:15 +0x168 ================== ================== WARNING: DATA RACE Read at 0x00c42007c030 by goroutine 8: github.com/templexxx/fqueue.(*queue).Get() /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:112 +0x196 main.main.func4() /home/cholerae/test/gotest/testfqueue.go:36 +0x6e Previous write at 0x00c42007c030 by goroutine 5: github.com/templexxx/fqueue.(*queue).Push() /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:76 +0x17e main.main.func1() /home/cholerae/test/gotest/testfqueue.go:18 +0x9e Goroutine 8 (running) created at: main.main() /home/cholerae/test/gotest/testfqueue.go:33 +0x1ec Goroutine 5 (running) created at: main.main() /home/cholerae/test/gotest/testfqueue.go:15 +0x168 ================== ================== WARNING: DATA RACE Read at 0x00c42007c018 by goroutine 7: github.com/templexxx/fqueue.(*queue).Get() /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:112 +0x196 main.main.func3() /home/cholerae/test/gotest/testfqueue.go:30 +0x6b Previous write at 0x00c42007c018 by goroutine 5: github.com/templexxx/fqueue.(*queue).Push() /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:76 +0x17e main.main.func1() /home/cholerae/test/gotest/testfqueue.go:18 +0x9e Goroutine 7 (running) created at: main.main() /home/cholerae/test/gotest/testfqueue.go:27 +0x1c0 Goroutine 5 (running) created at: main.main() /home/cholerae/test/gotest/testfqueue.go:15 +0x168 ================== ================== WARNING: DATA RACE Read at 0x00c42007d1d0 by goroutine 7: github.com/templexxx/fqueue.(*queue).Get() /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:112 +0x196 main.main.func3() /home/cholerae/test/gotest/testfqueue.go:30 +0x6b Previous write at 0x00c42007d1d0 by goroutine 5: [failed to restore the stack] Goroutine 7 (running) created at: main.main() /home/cholerae/test/gotest/testfqueue.go:27 +0x1c0 Goroutine 5 (running) created at: main.main() /home/cholerae/test/gotest/testfqueue.go:15 +0x168 ================== ================== WARNING: DATA RACE Read at 0x00c42007d1f8 by goroutine 8: github.com/templexxx/fqueue.(*queue).Get() /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:111 +0x15e main.main.func4() /home/cholerae/test/gotest/testfqueue.go:36 +0x6e Previous write at 0x00c42007d1f8 by goroutine 5: [failed to restore the stack] Goroutine 8 (running) created at: main.main() /home/cholerae/test/gotest/testfqueue.go:33 +0x1ec Goroutine 5 (running) created at: main.main() /home/cholerae/test/gotest/testfqueue.go:15 +0x168 ================== ================== WARNING: DATA RACE Read at 0x00c42007d210 by goroutine 7: github.com/templexxx/fqueue.(*queue).Get() /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:111 +0x15e main.main.func3() /home/cholerae/test/gotest/testfqueue.go:30 +0x6b Previous write at 0x00c42007d210 by goroutine 5: [failed to restore the stack] Goroutine 7 (running) created at: main.main() /home/cholerae/test/gotest/testfqueue.go:27 +0x1c0 Goroutine 5 (running) created at: main.main() /home/cholerae/test/gotest/testfqueue.go:15 +0x168 ================== ================== WARNING: DATA RACE Read at 0x00c42007d1e8 by goroutine 8: github.com/templexxx/fqueue.(*queue).Get() /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:112 +0x196 main.main.func4() /home/cholerae/test/gotest/testfqueue.go:36 +0x6e Previous write at 0x00c42007d1e8 by goroutine 5: [failed to restore the stack] Goroutine 8 (running) created at: main.main() /home/cholerae/test/gotest/testfqueue.go:33 +0x1ec Goroutine 5 (running) created at: main.main() /home/cholerae/test/gotest/testfqueue.go:15 +0x168 ================== ================== WARNING: DATA RACE Read at 0x00c4200b9738 by goroutine 7: github.com/templexxx/fqueue.(*queue).Get() /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:111 +0x15e main.main.func3() /home/cholerae/test/gotest/testfqueue.go:30 +0x6b Previous write at 0x00c4200b9738 by goroutine 6: github.com/templexxx/fqueue.(*queue).Push() /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:77 +0x1b8 main.main.func2() /home/cholerae/test/gotest/testfqueue.go:24 +0xa1 Goroutine 7 (running) created at: main.main() /home/cholerae/test/gotest/testfqueue.go:27 +0x1c0 Goroutine 6 (finished) created at: main.main() /home/cholerae/test/gotest/testfqueue.go:21 +0x194 ================== ================== WARNING: DATA RACE Read at 0x00c4200b9750 by goroutine 8: github.com/templexxx/fqueue.(*queue).Get() /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:111 +0x15e main.main.func4() /home/cholerae/test/gotest/testfqueue.go:36 +0x6e Previous write at 0x00c4200b9750 by goroutine 6: github.com/templexxx/fqueue.(*queue).Push() /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:77 +0x1b8 main.main.func2() /home/cholerae/test/gotest/testfqueue.go:24 +0xa1 Goroutine 8 (running) created at: main.main() /home/cholerae/test/gotest/testfqueue.go:33 +0x1ec Goroutine 6 (finished) created at: main.main() /home/cholerae/test/gotest/testfqueue.go:21 +0x194 ================== ================== WARNING: DATA RACE Read at 0x00c4200b9728 by goroutine 7: github.com/templexxx/fqueue.(*queue).Get() /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:112 +0x196 main.main.func3() /home/cholerae/test/gotest/testfqueue.go:30 +0x6b Previous write at 0x00c4200b9728 by goroutine 6: github.com/templexxx/fqueue.(*queue).Push() /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:76 +0x17e main.main.func2() /home/cholerae/test/gotest/testfqueue.go:24 +0xa1 Goroutine 7 (running) created at: main.main() /home/cholerae/test/gotest/testfqueue.go:27 +0x1c0 Goroutine 6 (finished) created at: main.main() /home/cholerae/test/gotest/testfqueue.go:21 +0x194 ================== ================== WARNING: DATA RACE Read at 0x00c4200b9740 by goroutine 8: github.com/templexxx/fqueue.(*queue).Get() /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:112 +0x196 main.main.func4() /home/cholerae/test/gotest/testfqueue.go:36 +0x6e Previous write at 0x00c4200b9740 by goroutine 6: github.com/templexxx/fqueue.(*queue).Push() /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:76 +0x17e main.main.func2() /home/cholerae/test/gotest/testfqueue.go:24 +0xa1 Goroutine 8 (running) created at: main.main() /home/cholerae/test/gotest/testfqueue.go:33 +0x1ec Goroutine 6 (finished) created at: main.main() /home/cholerae/test/gotest/testfqueue.go:21 +0x194 ================== Found 12 data race(s) exit status 66 ```