Provides a mutual exclusion lock primitive where a thread trying to acquire the lock waits in a loop repeatedly checking until the lock becomes available.
- Header
#include <xtd/threading/spin_lock>
- Namespace
- xtd::threading
- Library
- xtd.core
- Examples
- The following example shows how to use a xtd::threading::spin_lock:
|
| void | enter (bool &lock_taken) |
| | Acquires the lock in a reliable manner, such that even if an exception occurs within the method call, lock_taken can be examined reliably to determine whether the lock was acquired. More...
|
| |
| void | exit () |
| | Releases the lock. More...
|
| |
| void | exit (bool use_memory_barrier) |
| | Releases the lock. More...
|
| |
| void | try_enter (bool &lock_taken) |
| | Attempts to acquire the lock in a reliable manner, such that even if an exception occurs within the method call, lock_taken can be examined reliably to determine whether the lock was acquired. More...
|
| |
| void | try_enter (int32 milliseconds_timeout, bool &lock_taken) |
| | Attempts to acquire the lock in a reliable manner, such that even if an exception occurs within the method call, lock_taken can be examined reliably to determine whether the lock was acquired. More...
|
| |
| void | try_enter (const time_span &timeout, bool &lock_taken) |
| | Attempts to acquire the lock in a reliable manner, such that even if an exception occurs within the method call, lock_taken can be examined reliably to determine whether the lock was acquired. More...
|
| |
|
| | object ()=default |
| | Create a new instance of the ultimate base class object. More...
|
| |
| bool | equals (const object &obj) const noexcept |
| | Determines whether the specified object is equal to the current object. More...
|
| |
| virtual size_t | get_hash_code () const noexcept |
| | Serves as a hash function for a particular type. More...
|
| |
| virtual type_object | get_type () const noexcept |
| | Gets the type of the current instance. More...
|
| |
| template<typename object_t > |
| std::unique_ptr< object_t > | memberwise_clone () const noexcept |
| | Creates a shallow copy of the current object. More...
|
| |
| virtual xtd::ustring | to_string () const noexcept |
| | Returns a sxd::ustring that represents the current object. More...
|
| |
| static bool | equals (const object &object_a, const object &object_b) noexcept |
| | Determines whether the specified object instances are considered equal. More...
|
| |
| static bool | reference_equals (const object &object_a, const object &object_b) noexcept |
| | Determines whether the specified object instances are the same instance. More...
|
| |
◆ spin_lock() [1/2]
| xtd::threading::spin_lock::spin_lock |
( |
| ) |
|
◆ spin_lock() [2/2]
| xtd::threading::spin_lock::spin_lock |
( |
bool |
enable_thread_owner_tracking | ) |
|
Initializes a new instance of the xtd::threading::spin_lock structure with the option to track thread IDs to improve debugging.
- Parameters
-
| enable_thread_owner_tracking | Whether to capture and use thread IDs for debugging purposes. |
◆ enter()
| void xtd::threading::spin_lock::enter |
( |
bool & |
lock_taken | ) |
|
Acquires the lock in a reliable manner, such that even if an exception occurs within the method call, lock_taken can be examined reliably to determine whether the lock was acquired.
- Parameters
-
| lock_taken | True if the lock is acquired; otherwise, false. |
- Exceptions
-
◆ exit() [1/2]
| void xtd::threading::spin_lock::exit |
( |
| ) |
|
Releases the lock.
- Exceptions
-
◆ exit() [2/2]
| void xtd::threading::spin_lock::exit |
( |
bool |
use_memory_barrier | ) |
|
Releases the lock.
- Parameters
-
| use_memory_barrier | A bool value that indicates whether a memory fence should be issued in order to immediately publish the exit operation to other threads. |
- Exceptions
-
◆ is_held()
| bool xtd::threading::spin_lock::is_held |
( |
| ) |
const |
|
noexcept |
Gets whether the lock is currently held by any thread.
- Returns
- true if the lock is currently held by any thread; otherwise false.
◆ is_held_by_current_thread()
| bool xtd::threading::spin_lock::is_held_by_current_thread |
( |
| ) |
const |
|
noexcept |
Gets whether the lock is held by the current thread.
- Returns
- true if the lock is held by the current thread; otherwise false.
◆ is_thread_owner_tracking_enabled()
| bool xtd::threading::spin_lock::is_thread_owner_tracking_enabled |
( |
| ) |
const |
|
noexcept |
Gets whether thread ownership tracking is enabled for this instance.
- Returns
- true if thread ownership tracking is enabled for this instance; otherwise false.
◆ try_enter() [1/3]
| void xtd::threading::spin_lock::try_enter |
( |
bool & |
lock_taken | ) |
|
Attempts to acquire the lock in a reliable manner, such that even if an exception occurs within the method call, lock_taken can be examined reliably to determine whether the lock was acquired.
- Parameters
-
| lock_taken | True if the lock is acquired; otherwise, false. |
- Exceptions
-
◆ try_enter() [2/3]
| void xtd::threading::spin_lock::try_enter |
( |
int32 |
milliseconds_timeout, |
|
|
bool & |
lock_taken |
|
) |
| |
Attempts to acquire the lock in a reliable manner, such that even if an exception occurs within the method call, lock_taken can be examined reliably to determine whether the lock was acquired.
- Parameters
-
| milliseconds_timeout | The number of milliseconds to wait, or xtd::threading::timeout::infinite (-1) to wait indefinitely. |
| lock_taken | True if the lock is acquired; otherwise, false. |
- Exceptions
-
◆ try_enter() [3/3]
| void xtd::threading::spin_lock::try_enter |
( |
const time_span & |
timeout, |
|
|
bool & |
lock_taken |
|
) |
| |
Attempts to acquire the lock in a reliable manner, such that even if an exception occurs within the method call, lock_taken can be examined reliably to determine whether the lock was acquired.
- Parameters
-
| timeout | A xtd::time_span that represents the number of milliseconds to wait, or a xtd::time_span that represents -1 milliseconds to wait indefinitely. |
| lock_taken | True if the lock is acquired; otherwise, false. |
- Exceptions
-
The documentation for this class was generated from the following file: