SpinMutex Class Reference

#include <Pt/System/Mutex.h>

Spin mutex. More...

Inherits NonCopyable.

Public Member Functions

 SpinMutex ()
 Default Constructor.
 ~SpinMutex ()
 Destructor.
void lock ()
 Lock the mutex.
bool tryLock ()
 Tries to acquire a lock.
void unlock ()
 Unlocks the mutex.

Detailed Description

SpinMutex is the lightest mutex. lock() sets a locked status with an atomic operation. Another thread that calls lock() waits until unlock() clears that status. It is not recursive.

Use it only when the lock is held for a very short time. For a longer critical section use Mutex.

Member Function Documentation

◆ lock()

void lock ( )

Locks the Spinlock. If the Spinlock is currently locked by another thread, the calling thread suspends until no other thread holds a lock on it. This happens performing a busy-wait. Spinlocks are not recursive locking it multiple times before unlocking it is undefined.

◆ tryLock()

bool tryLock ( )

Immediately returns true if successful, or false if one or more other threads currently hold locks.