# Poco

# class AtomicFlag

Library: Foundation
Package: Core
Header: Poco/AtomicFlag.h

## Description

This class implements an atomic boolean flag by wrapping the std::atomic_flag. It is guaranteed to be thread-safe and lock-free.

Only default-construction is allowed, objects of this class are not copyable, assignable or movable.

Note that this class is not a replacement for (atomic) bool type because its value can not be read without also being set to true. However, after being set (either explicitly, through the set() call or implicitly, via operator bool()), it can be reset and reused.

The class is useful in scenarios such as busy-wait or one-off code blocks, e.g.:

class MyClass { public:

    void myFunc()
    {
        if (!_beenHere) doOnce();
        doMany();
    }

    void doOnce() { /* executed once */ }

    void doMany() { /* executed multiple times */ }

private:

    AtomicFlag _beenHere;

}

MyClass myClass; int i = 0; while (++i < 10) myClass.myFunc();

## Member Summary

Member Functions: operator =, operator bool, reset, set

## Constructors

### AtomicFlag

AtomicFlag() = default;

Creates AtomicFlag.

### AtomicFlag

AtomicFlag(
const AtomicFlag & param178
) = delete;

### AtomicFlag

AtomicFlag(
AtomicFlag && param180
) = delete;

## Destructor

### ~AtomicFlag

~AtomicFlag() = default;

Destroys AtomicFlag.

## Member Functions

### operator =

AtomicFlag & operator = (
const AtomicFlag & param179
) = delete;

### operator =

AtomicFlag & operator = (
AtomicFlag && param181
) = delete;

### operator bool

operator bool();

Sets the flag to true and returns previously held value.

### reset

void reset();

Resets the flag to false.

### set

bool set();

Sets the flag to true and returns previously held value.