Standard library / sync/atomic

atomic.Int32.Store()

Atomically replace the current value. Other shared data needs its own synchronization protocol. Expected stdout: '15\n'.

Formal Syntax & Structure

go syntaxgo
func (x *Int32) Store(val int32)

Parameters & Attributes

NameTypeDescription
valint32Value to store; context values should be request-scoped.

Working Example

Example Snippetgo
package main
import (  "fmt"  "sync/atomic")
func main() { var x atomic.Int32; x.Store(12); x.Store(15); fmt.Println(x.Load()) }
Go Reference