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:
@@ -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()
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user