Add an atomic Boolean type (#4)

* Add an atomic Boolean type

Fixes #2.

* Feedback from CR

- Rename Swap to Toggle
- Add a more Swap-like Swap

* Add boolToInt helper
This commit is contained in:
Akshay Shah
2016-05-30 11:10:24 -07:00
parent e1b75a466a
commit 7afff28c37
3 changed files with 71 additions and 0 deletions

View File

@@ -103,3 +103,20 @@ func TestStressUint64(t *testing.T) {
}()
}
}
func TestStressBool(t *testing.T) {
defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(_parallelism))
atom := NewBool(false)
for i := 0; i < _parallelism; i++ {
go func() {
for j := 0; j < _iterations; j++ {
atom.Load()
atom.Store(false)
atom.Swap(true)
atom.Load()
atom.Toggle()
atom.Toggle()
}
}()
}
}