Standard library / sync/atomic

atomic.Int32.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 *Int32) Add(delta int32) (new int32)

Parameters & Attributes

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

Return Value

(new int32)

New value after addition.

Working Example

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