[#BloombergLP-bsls-SpinLock]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bsls.adoc[bsls]::SpinLock
:relfileprefix: ../../
:mrdocs:

Statically&hyphen;initializable mutex that spins instead of blocking&period;

== Synopsis

Declared in `&lt;bsls&lowbar;spinlock&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
struct SpinLock;
----

== Description

A statically&hyphen;initializable synchronization primitive that &quot;spins&quot; (i&period;e&period;, executes user instructions in a tight loop) rather than blocking waiting threads using system calls&period; The following idiom is used to initialize `SpinLock` variables&colon; &grave; SpinLock lock &equals; BSLS&lowbar;SPINLOCK&lowbar;UNLOCKED&semi; &grave; A class member `d&lowbar;lock` of type `SpinLock` may be initialized using the following idiom&colon; &grave; , d&lowbar;lock(SpinLock&colon;&colon;s&lowbar;unlocked) &grave;

== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bsls/SpinLock/2constructor-01.adoc[`SpinLock`]         [.small]#[constructor]#
| Constructors
| xref:BloombergLP/bsls/SpinLock/lock.adoc[`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&period;
| xref:BloombergLP/bsls/SpinLock/lockWithBackoff.adoc[`lockWithBackoff`] 
| Acquire the lock, spinning with backoff until it is free&period;
| xref:BloombergLP/bsls/SpinLock/lockWithoutBackoff.adoc[`lockWithoutBackoff`] 
| Acquire the lock by spinning without backoff until it is free&period;
| xref:BloombergLP/bsls/SpinLock/tryLock.adoc[`tryLock`] 
| Attempt to acquire the lock, retrying up to `numRetries` times&period;
| xref:BloombergLP/bsls/SpinLock/unlock.adoc[`unlock`] 
| Release the lock&period; The behavior is undefined unless the current thread holds the lock&period;
|===


== Static Data Members

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bsls/SpinLock/s_unlocked.adoc[`s&lowbar;unlocked`] 
| Initializer for an unlocked spin lock&period;
|===



[.small]#Created with https://www.mrdocs.com[MrDocs]#
