mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: lock mheap_.speciallock when allocating synctest specials
Avoid racing use of mheap_.specialBubbleAlloc. Fixes #75134 Change-Id: I0c9140c18d2bca1e1c3387cd81230f0e8c9ac23e Reviewed-on: https://go-review.googlesource.com/c/go/+/699255 Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
d3be949ada
commit
5dcedd6550
2 changed files with 24 additions and 0 deletions
|
|
@ -779,6 +779,28 @@ func TestWaitGroupHeapAllocated(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Issue #75134: Many racing bubble associations.
|
||||||
|
func TestWaitGroupManyBubbles(t *testing.T) {
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
for range 100 {
|
||||||
|
wg.Go(func() {
|
||||||
|
synctest.Run(func() {
|
||||||
|
cancelc := make(chan struct{})
|
||||||
|
var wg2 sync.WaitGroup
|
||||||
|
for range 100 {
|
||||||
|
wg2.Go(func() {
|
||||||
|
<-cancelc
|
||||||
|
})
|
||||||
|
}
|
||||||
|
synctest.Wait()
|
||||||
|
close(cancelc)
|
||||||
|
wg2.Wait()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
}
|
||||||
|
|
||||||
func TestHappensBefore(t *testing.T) {
|
func TestHappensBefore(t *testing.T) {
|
||||||
// Use two parallel goroutines accessing different vars to ensure that
|
// Use two parallel goroutines accessing different vars to ensure that
|
||||||
// we correctly account for multiple goroutines in the bubble.
|
// we correctly account for multiple goroutines in the bubble.
|
||||||
|
|
|
||||||
|
|
@ -410,7 +410,9 @@ func getOrSetBubbleSpecial(p unsafe.Pointer, bubbleid uint64, add bool) (assoc i
|
||||||
} else if add {
|
} else if add {
|
||||||
// p is not associated with a bubble,
|
// p is not associated with a bubble,
|
||||||
// and we've been asked to add an association.
|
// and we've been asked to add an association.
|
||||||
|
lock(&mheap_.speciallock)
|
||||||
s := (*specialBubble)(mheap_.specialBubbleAlloc.alloc())
|
s := (*specialBubble)(mheap_.specialBubbleAlloc.alloc())
|
||||||
|
unlock(&mheap_.speciallock)
|
||||||
s.bubbleid = bubbleid
|
s.bubbleid = bubbleid
|
||||||
s.special.kind = _KindSpecialBubble
|
s.special.kind = _KindSpecialBubble
|
||||||
s.special.offset = offset
|
s.special.offset = offset
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue