Macaulay2 » Documentation
Packages » Macaulay2Doc » The Macaulay2 language » Thing » AtomicInt » exchange
next | previous | forward | backward | up | index | toc

# exchange -- exchange the value of an atomic integer

- Usage:
    `exchange(x, y)`
- Inputs:
  - x, an atomic integer,
  - y, an integer,
- Outputs:
  - an integer,

## Description

The value of y is stored in x and the original value of x is returned. This operation occurs atomically and is thread safe.

    i1 : x = new AtomicInt

    o1 = 0

    o1 : AtomicInt

    i2 : exchange(x, 5)

    o2 = 0

    i3 : x

    o3 = 5

    o3 : AtomicInt

## Ways to use exchange:

- `exchange(AtomicInt,ZZ)`

## For the programmer

The object exchange is a method function.

The source of this document is in /build/macaulay2-88fgJW/macaulay2-1.25.11+ds/M2/Macaulay2/packages/Macaulay2Doc/doc_atomic.m2:233:0.