Standard library / sync/atomic
atomic.OrInt64()
Atomically apply bitwise OR 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\n15\n'.
Formal Syntax & Structure
go syntaxgo
func OrInt64(addr *int64, mask int64) (old int64)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| addr | *int64 | Pointer to the shared variable; satisfy architecture alignment requirements and use atomic access consistently. |
| mask | int64 | Bit mask used by the atomic operation. |
Return Value
(old int64)
Previous value before OR.
Working Example
Example Snippetgo
package main
import ( "fmt" "sync/atomic")
func main() { x := new(int64) atomic.StoreInt64(x, 12) fmt.Println(atomic.OrInt64(x, 3)) fmt.Println(atomic.LoadInt64(x))}