Standard library / sync/atomic

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

Parameters & Attributes

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

Return Value

(new int64)

New value after addition.

Working Example

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