Standard library / sync/atomic
atomic.AddUint32()
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 AddUint32(addr *uint32, delta uint32) (new uint32)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| addr | *uint32 | Pointer to the shared variable; satisfy architecture alignment requirements and use atomic access consistently. |
| delta | uint32 | Amount to add; for WaitGroup, change in outstanding task count. |
Return Value
(new uint32)
New value after addition.
Working Example
Example Snippetgo
package main
import ( "fmt" "sync/atomic")
func main() { x := new(uint32) atomic.StoreUint32(x, 12) fmt.Println(atomic.AddUint32(x, 3)) fmt.Println(atomic.LoadUint32(x))}