...

Source file src/runtime/race/testdata/reflect_test.go

Documentation: runtime/race/testdata

     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  
     5  package race_test
     6  
     7  import (
     8  	"reflect"
     9  	"testing"
    10  )
    11  
    12  func 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  
    24  func 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  
    36  func 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  

View as plain text