commit | 40ae6a40a970ef4cdbffa7b24b280e316db8accc | [log] [tgz] |
---|---|---|
author | Prashant Varanasi <prashant@uber.com> | Tue Nov 19 13:33:40 2019 -0800 |
committer | GitHub <noreply@github.com> | Tue Nov 19 13:33:40 2019 -0800 |
tree | 0fb1896368f7af57a53ce718535479d829ddb4e5 | |
parent | b99530f7f5dd8e90ff39dedf1cafb4c89d7a5778 [diff] |
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.
Simple wrappers for primitive types to enforce atomic access.
$ go get -u go.uber.org/atomic@v1
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.Store(42)
atom.Sub(2)
atom.CAS(40, 11)
See the documentation for a complete API specification.
Stable.
Released under the MIT License.