commit | e81582a97d2dffa59c4cce87d076b4e372aeb62e | [log] [tgz] |
---|---|---|
author | Prashant Varanasi <github@prashantv.com> | Tue Nov 14 08:16:11 2017 -0800 |
committer | GitHub <noreply@github.com> | Tue Nov 14 08:16:11 2017 -0800 |
tree | bf99499509711dc74f03325d69be2fd0b98a9687 | |
parent | 54f72d32435d760d5604f17a82e2435b28dc4ba5 [diff] |
Revert "Optimization for String.Store("")" (#32) This optimization causes data races since we're changing the value field without using atomics. E.g., a caller who has multiple goroutines calling `Set("1")` and `Set("")` will race on the access to `s.v` since one goroutine is trying to read it while the other sets it, neither using atomic operations. This reverts commit 16b44f14f0990d358f2ba3191ff8e7c44c9f0bef.
Simple wrappers for primitive types to enforce atomic access.
go get -u go.uber.org/atomic
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.