I think the current implementations of the methods of sync.RWMutex happen 
to be actual memory barriers <https://en.wikipedia.org/wiki/Memory_barrier> 
and this is why everything works just fine.

But I don't think the spec or the memory model or the doc of sync mentions 
this.

If this is not described, the example in the memory model for the locks is 
wrong:

           // https://play.golang.org/p/pmhbeyn_wZ

var l sync.Mutex
var a string

func f() {
a = "hello, world"
l.Unlock()
}

func main() {
l.Lock()
go f()
l.Lock()
print(a)
}

 
The statements in f() might be reordered to run l.Unlock() first and then 
the assignment. The code would not guarantee to print "hello, world" at the 
end.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to