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

compareExchange -- compare and possibly exchange the value of an atomic integer

Description

The values of x and y are compared. If they agree, then true is returned and the value of z is stored in x. Otherwise, false is returned. This operation occurs atomically and is thread safe.

i1 : x = new AtomicInt

o1 = 0

o1 : AtomicInt
i2 : compareExchange(x, 2, 3)

o2 = false
i3 : x

o3 = 0

o3 : AtomicInt
i4 : compareExchange(x, 0, 3)

o4 = true
i5 : x

o5 = 3

o5 : AtomicInt

Ways to use compareExchange:

  • compareExchange(AtomicInt,ZZ,ZZ)

For the programmer

The object compareExchange is a method function.


The source of this document is in Macaulay2Doc/doc_atomic.m2:261:0.