On 2/26/2013 1:19 PM, Jan Mercl wrote:
On Tue, Feb 26, 2013 at 9:52 PM, John Nagle
wrote: Though you're
consistently "teaching" that it is the problem of the language, which
is not true.
If it wasn't a problem, the Go Playground and Google AppEngine
wouldn't be locked down to single-thread.
There are only a few events that force memory synchronization:
- Receive on a channel. - Unlock on a mutex lock.
It's simply not what is in the talked about document and AFAICS it
is not true. Please cite the document relevant parts and correctly
derive your result.
That comes from the statements in "http://golang.org/ref/mem":
"Within a single goroutine, the happens-before order is the order
expressed by the program."
"A send on a channel happens before the corresponding receive from that
channel completes."
"For any sync.Mutex or sync.RWMutex variable l and n < m, call n of
l.Unlock() happens before call m of l.Lock() returns."
Therefore, the user is guaranteed sequential operations from one
goroutine to another if a channel receive intervenes. The receive
is the synchronizing operation, not the send. Similarly, Unlock
(or really, return from Lock) is the synchronizing operation,
not Lock. This is as it should be.
Mercl is right, though; I'm oversimplifying. If one goroutine
sends to a channel that has some items queued, and the receiver gets
an item that was already in the channel, a Go implementation is not
strictly required to synchronize memory up to the last send to the
channel, only to the state at the time the item being read
entered the channel. In practice an implementation probably
does a global memory fence operation on each channel receive,
but the spec is a bit looser than that.
How strict is Go's race detector about this? Does it track
state through channel queues, or does it just treat some
events as a commit?
(I once spent several years fixing a major mainframe operating
system by reading crash dumps from production machines.
This makes one very aware of race conditions as defects.
I never want to do that again.)
John Nagle
--
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+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/groups/opt_out.