1
0
mirror of https://github.com/golang/go synced 2024-11-22 05:14:40 -07:00

sync: use atomic.Store in Once.Do

No perf/semantic changes, merely improves code health.
There were several questions as to why Once.Do uses
atomic.CompareAndSwap to do a store.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/6208057
This commit is contained in:
Dmitriy Vyukov 2012-05-14 19:27:29 +04:00
parent 58bcec62c0
commit 8c4c6c413f

View File

@ -38,6 +38,6 @@ func (o *Once) Do(f func()) {
defer o.m.Unlock()
if o.done == 0 {
f()
atomic.CompareAndSwapUint32(&o.done, 0, 1)
atomic.StoreUint32(&o.done, 1)
}
}