Documentation ¶
Overview ¶
Package atomicx extends sync/atomic.
Sync/atomic fails when using int64 atomic operations on 32 bit platforms when the access is not aligned. As specified in the documentation, in fact, "it is the caller's responsibility to arrange for 64-bit alignment of 64-bit words accessed atomically". For more information on this issue, see https://golang.org/pkg/sync/atomic/#pkg-note-BUG.
As explained in CONTRIBUTING.md, probe-cli SHOULD use this package rather than sync/atomic to avoid these alignment issues on 32 bit.
It is of course possible to write atomic code using 64 bit variables on a 32 bit platform, but that's difficult to do correctly. This package provides an easier-to-use interface. We use allocated structures protected by a mutex that encapsulate a int64 value.
Example (TypicalUsage) ¶
package main import ( "fmt" "github.com/ooni/probe-cli/v3/internal/atomicx" ) func main() { v := &atomicx.Int64{} v.Add(1) fmt.Printf("%d\n", v.Load()) }
Output: 1
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.