...
Source file
src/runtime/race/race_unix_test.go
1
2
3
4
5
6
7 package race_test
8
9 import (
10 "sync/atomic"
11 "syscall"
12 "testing"
13 "unsafe"
14 )
15
16
17 func TestNonGoMemory(t *testing.T) {
18 data, err := syscall.Mmap(-1, 0, 4096, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_ANON|syscall.MAP_PRIVATE)
19 if err != nil {
20 t.Fatalf("failed to mmap memory: %v", err)
21 }
22 defer syscall.Munmap(data)
23 p := (*uint32)(unsafe.Pointer(&data[0]))
24 atomic.AddUint32(p, 1)
25 (*p)++
26 if *p != 2 {
27 t.Fatalf("data[0] = %v, expect 2", *p)
28 }
29 }
30
View as plain text