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