Standard library / sync/atomic

atomic.Pointer.Load()

Atomically read the stored pointer; check nil before dereferencing. Expected stdout: '7\n'.

Formal Syntax & Structure

go syntaxgo
func (x *Pointer[T]) Load() *T

Return Value

*T

Current pointer or nil.

Working Example

Example Snippetgo
package main
import (  "fmt"  "sync/atomic")
func main() { a, b := 7, 9; _ = b; var x atomic.Pointer[int]; x.Store(&a); fmt.Println(*x.Load()) }
Go Reference