-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexample_test.go
More file actions
54 lines (43 loc) · 762 Bytes
/
Copy pathexample_test.go
File metadata and controls
54 lines (43 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package safetyfast
func ExampleHLE() {
m := map[string]int{
"word1": 0,
"word2": 0,
"word3": 0,
"word4": 0,
}
var lock SpinHLEMutex
lock.Lock()
// Action to be done transactionally
count := m["word1"]
m["word1"] = count + 1
lock.Unlock()
}
func ExampleHLE2() {
m := map[string]int{
"word1": 0,
"word2": 0,
"word3": 0,
"word4": 0,
}
c := NewLockedContext(new(SpinHLEMutex))
c.Atomic(func() {
// Action to be done transactionally
count := m["word1"]
m["word1"] = count + 1
})
}
func ExampleRTM() {
m := map[string]int{
"word1": 0,
"word2": 0,
"word3": 0,
"word4": 0,
}
c := NewRTMContexDefault()
c.Atomic(func() {
// Action to be done transactionally
count := m["word1"]
m["word1"] = count + 1
})
}