Documentation Home >> Headers >> <atomic> Header >> std::atomic_flag class

The std::atomic_flag class provides a simple bare-bones atomic flag. It is the only data type that is guaranteed to be lock-free by the C++11 standard (though many atomic types are lock-free in just::thread).

An instance of std::atomic_flag is either set or clear.

struct atomic_flag
{
    atomic_flag() = default;
    atomic_flag(const atomic_flag&) = delete;
    atomic_flag& operator=(
        const atomic_flag&) = delete;

    bool test_and_set(
        memory_order = memory_order_seq_cst) volatile;
    void clear(
        memory_order = memory_order_seq_cst) volatile;
};

bool atomic_flag_test_and_set(volatile atomic_flag*);
bool atomic_flag_test_and_set_explicit(
    volatile atomic_flag*, memory_order);
void atomic_flag_clear(volatile atomic_flag*);
void atomic_flag_clear_explicit(
    volatile atomic_flag*, memory_order);

#define ATOMIC_FLAG_INIT unspecified
Header

#include <atomic>

See Also