Standard library / sync/atomic

atomic.OrUint32()

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 OrUint32(addr *uint32, mask uint32) (old uint32)

Parameters & Attributes

NameTypeDescription
addr*uint32Pointer to the shared variable; satisfy architecture alignment requirements and use atomic access consistently.
maskuint32Bit mask used by the atomic operation.

Return Value

(old uint32)

Previous value before OR.

Working Example

Example Snippetgo
package main
import (  "fmt"  "sync/atomic")
func main() {  x := new(uint32)  atomic.StoreUint32(x, 12)  fmt.Println(atomic.OrUint32(x, 3))  fmt.Println(atomic.LoadUint32(x))}
Go Reference