| 1 |
// run |
| 2 |
|
| 3 |
// Copyright 2021 The Go Authors. All rights reserved. |
| 4 |
// Use of this source code is governed by a BSD-style |
| 5 |
// license that can be found in the LICENSE file. |
| 6 |
|
| 7 |
// Gccgo did not make a copy of a value receiver when using a |
| 8 |
// goroutine to call a method. |
| 9 |
|
| 10 |
package main |
| 11 |
|
| 12 |
import ( |
| 13 |
"sync" |
| 14 |
"sync/atomic" |
| 15 |
) |
| 16 |
|
| 17 |
var wg sync.WaitGroup |
| 18 |
|
| 19 |
type S struct { |
| 20 |
i1, i2 int32 |
| 21 |
} |
| 22 |
|
| 23 |
var done int32 |
| 24 |
|
| 25 |
func (s S) Check(v1, v2 int32) { |
| 26 |
for { |
| 27 |
if g1 := atomic.LoadInt32(&s.i1); v1 != g1 { |
| 28 |
panic(g1) |
| 29 |
} |
| 30 |
if g2 := atomic.LoadInt32(&s.i2); v2 != g2 { |
| 31 |
panic(g2) |
| 32 |
} |
| 33 |
if atomic.LoadInt32(&done) != 0 { |
| 34 |
break |
| 35 |
} |
| 36 |
} |
| 37 |
wg.Done() |
| 38 |
} |
| 39 |
|
| 40 |
func F() { |
| 41 |
s := S{1, 2} |
| 42 |
go s.Check(1, 2) |
| 43 |
atomic.StoreInt32(&s.i1, 3) |
| 44 |
atomic.StoreInt32(&s.i2, 4) |
| 45 |
atomic.StoreInt32(&done, 1) |
| 46 |
} |
| 47 |
|
| 48 |
func main() { |
| 49 |
wg.Add(1) |
| 50 |
F() |
| 51 |
wg.Wait() |
| 52 |
} |