Modify Bool to only use 1 or 0, rater than last bit (#62)

Most methods of Bool currently rely on the last bit, but `CAS`
generates the int value to match `old` based on the user's input
and so it assumes the value is either `1` or `0`.

The only reason we relid on the last bit is that `Toggle` was
implemented using an atomic add. We can instead implement
`Toggle` using a loop around `CAS`.

Fixes #61.
3 files changed
tree: 0fb1896368f7af57a53ce718535479d829ddb4e5
  1. .codecov.yml
  2. .github/
  3. .gitignore
  4. .travis.yml
  6. LICENSE.txt
  7. Makefile
  8. README.md
  9. atomic.go
  10. atomic_test.go
  11. error.go
  12. error_test.go
  13. example_test.go
  14. go.mod
  15. go.sum
  16. stress_test.go
  17. string.go
  18. string_test.go
  19. tools.go

atomic GoDoc Build Status Coverage Status Go Report Card

Simple wrappers for primitive types to enforce atomic access.


$ go get -u go.uber.org/atomic@v1

Legacy Import Path

As of v1.5.0, the import path go.uber.org/atomic is the only supported way of using this package. If you are using Go modules, this package will fail to compile with the legacy import path path github.com/uber-go/atomic.

We recommend migrating your code to the new import path but if you're unable to do so, or if your dependencies are still using the old import path, you will have to add a replace directive to your go.mod file downgrading the legacy import path to an older version.

replace github.com/uber-go/atomic => github.com/uber-go/atomic v1.4.0

You can do so automatically by running the following command.

$ go mod edit -replace github.com/uber-go/atomic=github.com/uber-go/atomic@v1.4.0


The standard library‘s sync/atomic is powerful, but it’s easy to forget which variables must be accessed atomically. go.uber.org/atomic preserves all the functionality of the standard library, but wraps the primitive types to provide a safer, more convenient API.

var atom atomic.Uint32
atom.CAS(40, 11)

See the documentation for a complete API specification.

Development Status


Released under the MIT License.