Standard library / sync/atomic
atomic.AndUint64()
Atomically apply bitwise AND and return the previous value (Go 1.23+). Raw pointer APIs require correctly aligned storage; prefer the corresponding typed atomic in new code. Expected stdout: '12\n8\n'.
Formal Syntax & Structure
go syntaxgo
func AndUint64(addr *uint64, mask uint64) (old uint64)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| addr | *uint64 | Pointer to the shared variable; satisfy architecture alignment requirements and use atomic access consistently. |
| mask | uint64 | Bit mask used by the atomic operation. |
Return Value
(old uint64)
Previous value before AND.
Working Example
Example Snippetgo
package main
import ( "fmt" "sync/atomic")
func main() { x := new(uint64) atomic.StoreUint64(x, 12) fmt.Println(atomic.AndUint64(x, 10)) fmt.Println(atomic.LoadUint64(x))}