【发布时间】:2012-10-17 15:51:05
【问题描述】:
Go 的缓冲通道本质上是一个线程安全的 FIFO 队列。 (见Is it possible to use Go's buffered channel as a thread-safe queue?)
我想知道它是如何实现的。是否像Is there such a thing as a lockless queue for multiple read or write threads? 中描述的那样无锁?
在 Go 的 src 目录 (grep -r Lock .|grep chan) 中 greping 会得到以下输出:
./pkg/runtime/chan.c: Lock;
./pkg/runtime/chan_test.go: m.Lock()
./pkg/runtime/chan_test.go: m.Lock() // wait
./pkg/sync/cond.go: L Locker // held while observing or changing the condition
虽然不会锁定我的机器(MacOS,intel x86_64)。是否有任何官方资源可以验证这一点?
【问题讨论】:
标签: thread-safety go lockless