Standard library / sync/atomic
atomic.Pointer
Typed atomic pointer with initial nil value. Atomics protect the pointer, not mutations of the pointed-to object. Do not copy after first use. Expected stdout: 'true\n7\n'.
Formal Syntax & Structure
go syntaxgo
type Pointer[T any] struct {}Working Example
Example Snippetgo
package main
import ( "fmt" "sync/atomic")
func main() { a, b := 7, 9 _ = b var x atomic.Pointer[int] fmt.Println(x.Load() == nil) x.Store(&a) fmt.Println(*x.Load())}