spin_mutex

[mutex.spin_mutex]

A spin_mutext is a class that models the Mutex requirement using a spin lock. The spin_mutex class satisfies all requirements of mutex type from the [thread.mutex.requirements] ISO C++ section. The spin_mutex class is not fair or recursive.

// Defined in header <tbb/spin_mutex.h>

namespace tbb {
    class spin_mutex {
    public:
        spin_mutex() noexcept;
        ~spin_mutex();

        spin_mutex(const spin_mutex&) = delete;
        spin_mutex& operator=(const spin_mutex&) = delete;

        class scoped_lock;

        void lock();
        bool try_lock();
        void unlock();

        static constexpr bool is_rw_mutex = false;
        static constexpr bool is_recursive_mutex = false;
        static constexpr bool is_fair_mutex = false;
    };
}

Member classes

class scoped_lock

Corresponding scoped_lock class. See the Mutex requirement.

Member functions

spin_mutex()

Constructs spin_mutex with unlocked state.

~spin_mutex()

Destroys an unlocked spin_mutex.

void lock()

Acquires a lock. Spins if the lock is taken.

bool try_lock()

Attempts to acquire a lock (non-blocking). Returns true if lock is acquired; false, otherwise.

void unlock()

Releases a lock held by a current thread.