Source file
test/escape_sync_atomic.go
1
2
3
4
5
6
7
8
9 package escape
10
11 import (
12 "sync/atomic"
13 "unsafe"
14 )
15
16
17 func LoadPointer(addr *unsafe.Pointer) unsafe.Pointer {
18 return atomic.LoadPointer(addr)
19 }
20
21 var ptr unsafe.Pointer
22
23 func StorePointer() {
24 var x int
25 atomic.StorePointer(&ptr, unsafe.Pointer(&x))
26 }
27
28 func SwapPointer() {
29 var x int
30 atomic.SwapPointer(&ptr, unsafe.Pointer(&x))
31 }
32
33 func CompareAndSwapPointer() {
34
35 var x int
36 var y int
37 atomic.CompareAndSwapPointer(&ptr, unsafe.Pointer(&x), unsafe.Pointer(&y))
38 }
39
View as plain text