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 p := (*uint32)(unsafe.Pointer(&data[0]))
23 atomic.AddUint32(p, 1)
24 (*p)++
25 if *p != 2 {
26 t.Fatalf("data[0] = %v, expect 2", *p)
27 }
28 syscall.Munmap(data)
29 }
30
View as plain text