Standard library / sync/atomic
atomic.LoadUint64()
Atomically read the current value. Use atomic access consistently for a concurrently shared location. Raw pointer APIs require correctly aligned storage; prefer the corresponding typed atomic in new code. Expected stdout: '12\n12\n'.
Formal Syntax & Structure
go syntaxgo
func LoadUint64(addr *uint64) (val uint64)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| addr | *uint64 | Pointer to the shared variable; satisfy architecture alignment requirements and use atomic access consistently. |
Return Value
(val uint64)
Current value.
Working Example
Example Snippetgo
package main
import ( "fmt" "sync/atomic")
func main() { x := new(uint64) atomic.StoreUint64(x, 12) fmt.Println(atomic.LoadUint64(x)) fmt.Println(atomic.LoadUint64(x))}