Standard library / sync/atomic
atomic.AddUint64()
Atomically add delta and return the new value. Integer overflow follows the type width. Raw pointer APIs require correctly aligned storage; prefer the corresponding typed atomic in new code. Expected stdout: '15\n15\n'.
Formal Syntax & Structure
go syntaxgo
func AddUint64(addr *uint64, delta uint64) (new uint64)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| addr | *uint64 | Pointer to the shared variable; satisfy architecture alignment requirements and use atomic access consistently. |
| delta | uint64 | Amount to add; for WaitGroup, change in outstanding task count. |
Return Value
(new uint64)
New value after addition.
Working Example
Example Snippetgo
package main
import ( "fmt" "sync/atomic")
func main() { x := new(uint64) atomic.StoreUint64(x, 12) fmt.Println(atomic.AddUint64(x, 3)) fmt.Println(atomic.LoadUint64(x))}