Standard library / sync/atomic

atomic.LoadInt32()

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 LoadInt32(addr *int32) (val int32)

Parameters & Attributes

NameTypeDescription
addr*int32Pointer to the shared variable; satisfy architecture alignment requirements and use atomic access consistently.

Return Value

(val int32)

Current value.

Working Example

Example Snippetgo
package main
import (  "fmt"  "sync/atomic")
func main() {  x := new(int32)  atomic.StoreInt32(x, 12)  fmt.Println(atomic.LoadInt32(x))  fmt.Println(atomic.LoadInt32(x))}
Go Reference