Standard library / sync/atomic

atomic.Uint64.Add()

Atomically add delta and return the new value. Integer overflow follows the type width. Expected stdout: '15\n15\n'.

Formal Syntax & Structure

go syntaxgo
func (x *Uint64) Add(delta uint64) (new uint64)

Parameters & Attributes

NameTypeDescription
deltauint64Amount to add; for WaitGroup, change in outstanding task count.

Return Value

(new uint64)

New value after addition.

Working Example

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