wxWidgets: Atomic Operations

| Version: 3.0.2

- Main Page
- Related Pages
- Categories
- Classes
- Files

Functions
Atomic Operations
Functions and Macros by Category

## Detailed Description

When using multi-threaded applications, it is often required to access or modify memory which is shared between threads.

Atomic integer and pointer operations are an efficient way to handle this issue (another, less efficient, way is to use a wxMutex or wxCriticalSection). A native implementation exists for Windows, Linux, Solaris and Mac OS X; for others, a wxCriticalSection is used to protect the data.

One particular application is reference counting (used by so-called smart pointers).

You should define your variable with the type wxAtomicInt in order to apply atomic operations to it.

## Functions
void | wxAtomicInc (wxAtomicInt &value)
| This function increments value in an atomic manner.
wxInt32 | wxAtomicDec (wxAtomicInt &value)
| This function decrements value in an atomic manner.

## Function Documentation

wxInt32 wxAtomicDec | ( | wxAtomicInt & | value | ) |

This function decrements value in an atomic manner.

Returns 0 if value is 0 after decrement or any non-zero value (not necessarily equal to the value of the variable) otherwise.

See Also
  wxAtomicInc

Include file:

    #include <wx/atomic.h>

void wxAtomicInc | ( | wxAtomicInt & | value | ) |

This function increments value in an atomic manner.

Whenever possible wxWidgets provides an efficient, CPU-specific, implementation of this function. If such implementation is available, the symbol wxHAS_ATOMIC_OPS is defined. Otherwise this function still exists but is implemented in a generic way using a critical section which can be prohibitively expensive for use in performance-sensitive code.

Include file:

    #include <wx/atomic.h>