Macaulay2 » Documentation
Packages » Macaulay2Doc :: compareExchange
next | previous | forward | backward | up | index | toc

compareExchange -- compares and possibly exchanges the value of an atomic integer

Synopsis

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 :

For the programmer

The object compareExchange is a method function.