diff options
author | Russ Cox <rsc@golang.org> | 2015-07-11 11:53:58 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2015-07-13 19:10:22 +0000 |
commit | 8c3533c89bae3493df8a0aad23e56c84f8d25714 (patch) | |
tree | fbb1bb3e3bfc4202e28b9bb39a5c7e2ae177ddf0 /src/runtime/chan.go | |
parent | 242ec168c1394038cee17935f92e28fc24baac8e (diff) | |
download | go-8c3533c89bae3493df8a0aad23e56c84f8d25714.tar.gz go-8c3533c89bae3493df8a0aad23e56c84f8d25714.zip |
runtime: add memory barrier for sync send in select
Missed select case when adding the barrier last time.
All the more reason to refactor this code in Go 1.6.
Fixes #11643.
Change-Id: Ib0d19d6e0939296c0a3e06dda5e9b76f813bbc7e
Reviewed-on: https://go-review.googlesource.com/12086
Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/chan.go')
-rw-r--r-- | src/runtime/chan.go | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/runtime/chan.go b/src/runtime/chan.go index a9eb83aeb3..cfee12a551 100644 --- a/src/runtime/chan.go +++ b/src/runtime/chan.go @@ -165,17 +165,7 @@ func chansend(t *chantype, c *hchan, ep unsafe.Pointer, block bool, callerpc uin recvg := sg.g if sg.elem != nil { - // This is the only place in the entire runtime where one goroutine - // writes to the stack of another goroutine. The GC assumes that - // stack writes only happen when the goroutine is running and are - // only done by that goroutine. Using a write barrier is sufficient to - // make up for violating that assumption, but the write barrier has to work. - // typedmemmove will call heapBitsBulkBarrier, but the target bytes - // are not in the heap, so that will not help. We arrange to call - // memmove and typeBitsBulkBarrier instead. - memmove(sg.elem, ep, c.elemtype.size) - typeBitsBulkBarrier(c.elemtype, uintptr(sg.elem), c.elemtype.size) - sg.elem = nil + syncsend(c, sg, ep) } recvg.param = unsafe.Pointer(sg) if sg.releasetime != 0 { @@ -287,6 +277,21 @@ func chansend(t *chantype, c *hchan, ep unsafe.Pointer, block bool, callerpc uin return true } +func syncsend(c *hchan, sg *sudog, elem unsafe.Pointer) { + // Send on unbuffered channel is the only operation + // in the entire runtime where one goroutine + // writes to the stack of another goroutine. The GC assumes that + // stack writes only happen when the goroutine is running and are + // only done by that goroutine. Using a write barrier is sufficient to + // make up for violating that assumption, but the write barrier has to work. + // typedmemmove will call heapBitsBulkBarrier, but the target bytes + // are not in the heap, so that will not help. We arrange to call + // memmove and typeBitsBulkBarrier instead. + memmove(sg.elem, elem, c.elemtype.size) + typeBitsBulkBarrier(c.elemtype, uintptr(sg.elem), c.elemtype.size) + sg.elem = nil +} + func closechan(c *hchan) { if c == nil { panic("close of nil channel") |