BloombergLP::bsls::SpinLock

Statically-initializable mutex that spins instead of blocking.

Synopsis

Declared in <bsls_spinlock.h>

struct SpinLock;

Description

A statically-initializable synchronization primitive that "spins" (i.e., executes user instructions in a tight loop) rather than blocking waiting threads using system calls. The following idiom is used to initialize SpinLock variables: ` SpinLock lock = BSLS_SPINLOCK_UNLOCKED; ` A class member d_lock of type SpinLock may be initialized using the following idiom: ` , d_lock(SpinLock::s_unlocked) `

Member Functions

NameDescription
SpinLock [constructor]Constructors
lock Spin (repeat a loop continuously without using the system to pause or reschedule the thread) until this object is unlocked, then atomically acquire the lock.
lockWithBackoff Acquire the lock, spinning with backoff until it is free.
lockWithoutBackoff Acquire the lock by spinning without backoff until it is free.
tryLock Attempt to acquire the lock, retrying up to numRetries times.
unlock Release the lock. The behavior is undefined unless the current thread holds the lock.

Static Data Members

NameDescription
s_unlocked Initializer for an unlocked spin lock.