Standard library / sync/atomic
atomic.Uint32.Swap()
Atomically replace the value and return the old value. Expected stdout: '12\n15\n'.
Formal Syntax & Structure
go syntaxgo
func (x *Uint32) Swap(new uint32) (old uint32)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| new | uint32 | Replacement value. |
Return Value
(old uint32)
Previous value.
Working Example
Example Snippetgo
package main
import ( "fmt" "sync/atomic")
func main() { var x atomic.Uint32; x.Store(12); fmt.Println(x.Swap(15)); fmt.Println(x.Load()) }