Standard library / sync/atomic
atomic.Pointer.Store()
Atomically publish a pointer. Treat published objects as immutable or synchronize their mutations separately. Expected stdout: '7\n'.
Formal Syntax & Structure
go syntaxgo
func (x *Pointer[T]) Store(val *T)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| val | *T | Value to store; context values should be request-scoped. |
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()) }