1// Copyright 2016 The Go Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style 3// license that can be found in the LICENSE file. 4 5package race_test 6 7import ( 8 "reflect" 9 "testing" 10) 11 12func TestRaceReflectRW(t *testing.T) { 13 ch := make(chan bool, 1) 14 i := 0 15 v := reflect.ValueOf(&i) 16 go func() { 17 v.Elem().Set(reflect.ValueOf(1)) 18 ch <- true 19 }() 20 _ = v.Elem().Int() 21 <-ch 22} 23 24func TestRaceReflectWW(t *testing.T) { 25 ch := make(chan bool, 1) 26 i := 0 27 v := reflect.ValueOf(&i) 28 go func() { 29 v.Elem().Set(reflect.ValueOf(1)) 30 ch <- true 31 }() 32 v.Elem().Set(reflect.ValueOf(2)) 33 <-ch 34} 35 36func TestRaceReflectCopyWW(t *testing.T) { 37 ch := make(chan bool, 1) 38 a := make([]byte, 2) 39 v := reflect.ValueOf(a) 40 go func() { 41 reflect.Copy(v, v) 42 ch <- true 43 }() 44 reflect.Copy(v, v) 45 <-ch 46} 47