Provides a mechanism that synchronizes access to objects.
Action | Description |
---|---|
xtd::threading::monitor::enter, xtd::threading::monitor::try_enter | Acquires a lock for an object. This action also marks the beginning of a critical section. No other thread can enter the critical section unless it is executing the instructions in the critical section using a different locked object. |
xtd::threading::monitor::wait | Releases the lock on an object in order to permit other threads to lock and access the object. The calling thread waits while another thread accesses the object. xtd::threading::monitor::pulse signals are used to notify waiting threads about changes to an object's state. |
xtd::threading::monitor::pulse, xtd::threading::monitor::pulse_all | Sends a signal to one or more waiting threads. The signal notifies a waiting thread that the state of the locked object has changed, and the owner of the lock is ready to release the lock. The waiting thread is placed in the object's ready queue so that it might eventually receive the lock for the object. Once the thread has the lock, it can check the new state of the object to see if the required state has been reached. |
xtd::threading::monitor::exit | Releases the lock on an object. This action also marks the end of a critical section protected by the locked object. |
true
if the lock is acquired, even if an exception is thrown when acquiring the lock. Use these overloads if it is critical to release the lock in all cases, even when the resources the lock is protecting might not be in a consistent state. Public Static Methods | |
template<class object_t > | |
static void | enter (const object_t &obj) |
Acquires an exclusive lock on the specified obj. | |
template<class object_t > | |
static void | enter (const object_t &obj, bool &lock_taken) |
Acquires an exclusive lock on the specified obj. | |
template<class object_t > | |
static void | exit (const object_t &obj) |
Releases an exclusive lock on the specified obj. | |
template<class object_t > | |
static bool | is_entered (const object_t &obj) |
Determines whether the current thread holds the lock on the specified object. | |
template<class object_t > | |
static void | pulse (const object_t &obj) |
Notifies a thread in the waiting queue of a change in the locked object's state. | |
template<class object_t > | |
static void | pulse_all (const object_t &obj) |
Notifies all waiting threads of a change in the object's state. | |
template<class object_t > | |
static bool | try_enter (const object_t &obj) noexcept |
Attempts to acquire an exclusive lock on the specified object. | |
template<class object_t > | |
static bool | try_enter (const object_t &obj, bool &lock_taken) noexcept |
Attempts to acquire an exclusive lock on the specified object. | |
template<class object_t > | |
static bool | try_enter (const object_t &obj, int32 milliseconds_timeout) noexcept |
Attempts, for the specified number of milliseconds, to acquire an exclusive lock on the specified object. | |
template<class object_t > | |
static bool | try_enter (const object_t &obj, int32 milliseconds_timeout, bool &lock_taken) noexcept |
Attempts, for the specified number of milliseconds, to acquire an exclusive lock on the specified object. | |
template<class object_t > | |
static bool | try_enter (const object_t &obj, int64 milliseconds_timeout) noexcept |
Attempts, for the specified number of milliseconds, to acquire an exclusive lock on the specified object. | |
template<class object_t > | |
static bool | try_enter (const object_t &obj, int64 milliseconds_timeout, bool &lock_taken) noexcept |
Attempts, for the specified number of milliseconds, to acquire an exclusive lock on the specified object. | |
template<class object_t > | |
static bool | try_enter (const object_t &obj, const time_span &timeout) noexcept |
Attempts, for the specified amount of time, to acquire an exclusive lock on the specified object. | |
template<class object_t > | |
static bool | try_enter (const object_t &obj, const time_span &timeout, bool &lock_taken) noexcept |
Attempts, for the specified amount of time, to acquire an exclusive lock on the specified object. | |
template<class object_t > | |
static bool | wait (const object_t &obj, int32 milliseconds_timeout) |
Releases the lock on an object and blocks the current thread until it reacquires the lock. If the specified time-out interval elapses, the thread enters the ready queue. | |
template<class object_t > | |
static bool | wait (const object_t &obj, const time_span &timeout) |
Releases the lock on an object and blocks the current thread until it reacquires the lock. If the specified time-out interval elapses, the thread enters the ready queue. | |
template<class object_t > | |
static bool | wait (const object_t &obj) |
Releases the lock on an object and blocks the current thread until it reacquires the lock. | |
|
inlinestatic |
Acquires an exclusive lock on the specified obj.
obj | The object on which to acquire the monitor lock. |
|
inlinestatic |
Acquires an exclusive lock on the specified obj.
obj | The object on which to acquire the monitor lock. |
lock_taken | The result of the attempt to acquire the lock, passed by reference. The input must be false . The output is true if the lock is acquired; otherwise, the output is false . The output is set even if an exception occurs during the attempt to acquire the lock. |
true
.
|
inlinestatic |
Releases an exclusive lock on the specified obj.
obj | The object on which to release the lock. |
|
inlinestatic |
Determines whether the current thread holds the lock on the specified object.
obj | The object to test. |
true
if the current thread holds the lock on obj; otherwise, false
.
|
inlinestatic |
Notifies a thread in the waiting queue of a change in the locked object's state.
obj | The object a thread is waiting for. |
xtd::threading::synchronization_lock_exception | The calling thread does not own the lock for the specified object. |
|
inlinestatic |
Notifies all waiting threads of a change in the object's state.
obj | The object a thread is waiting for. |
xtd::threading::synchronization_lock_exception | The calling thread does not own the lock for the specified object. |
|
inlinestaticnoexcept |
Attempts to acquire an exclusive lock on the specified object.
obj | The object on which to acquire the lock. |
true
if the current thread acquires the lock; otherwise, false
false
, and the thread does not enter the critical section.
|
inlinestaticnoexcept |
Attempts to acquire an exclusive lock on the specified object.
obj | The object on which to acquire the lock. |
lock_taken | The result of the attempt to acquire the lock, passed by reference. The input must be false . The output is true if the lock is acquired; otherwise, the output is false . The output is set even if an exception occurs during the attempt to acquire the lock. |
true
. true
if the current thread acquires the lock; otherwise, false
false
, and the thread does not enter the critical section.
|
inlinestaticnoexcept |
Attempts, for the specified number of milliseconds, to acquire an exclusive lock on the specified object.
obj | The object on which to acquire the lock. |
milliseconds_timeout | The number of milliseconds to wait for the lock. |
true
if the current thread acquires the lock; otherwise, false
|
inlinestaticnoexcept |
Attempts, for the specified number of milliseconds, to acquire an exclusive lock on the specified object.
obj | The object on which to acquire the lock. |
milliseconds_timeout | The number of milliseconds to wait for the lock. |
lock_taken | The result of the attempt to acquire the lock, passed by reference. The input must be false . The output is true if the lock is acquired; otherwise, the output is false . The output is set even if an exception occurs during the attempt to acquire the lock. |
true
. true
if the current thread acquires the lock; otherwise, false
|
inlinestaticnoexcept |
Attempts, for the specified number of milliseconds, to acquire an exclusive lock on the specified object.
obj | The object on which to acquire the lock. |
milliseconds_timeout | The number of milliseconds to wait for the lock. |
true
if the current thread acquires the lock; otherwise, false
|
inlinestaticnoexcept |
Attempts, for the specified number of milliseconds, to acquire an exclusive lock on the specified object.
obj | The object on which to acquire the lock. |
milliseconds_timeout | The number of milliseconds to wait for the lock. |
lock_taken | The result of the attempt to acquire the lock, passed by reference. The input must be false . The output is true if the lock is acquired; otherwise, the output is false . The output is set even if an exception occurs during the attempt to acquire the lock. |
true
. true
if the current thread acquires the lock; otherwise, false
|
inlinestaticnoexcept |
Attempts, for the specified amount of time, to acquire an exclusive lock on the specified object.
obj | The object on which to acquire the lock. |
timeout | A time_span representing the amount of time to wait for the lock. A value of -1 millisecond specifies an infinite wait. |
true
if the current thread acquires the lock; otherwise, false
|
inlinestaticnoexcept |
Attempts, for the specified amount of time, to acquire an exclusive lock on the specified object.
obj | The object on which to acquire the lock. |
timeout | A time_span representing the amount of time to wait for the lock. A value of -1 millisecond specifies an infinite wait. |
lock_taken | The result of the attempt to acquire the lock, passed by reference. The input must be false . The output is true if the lock is acquired; otherwise, the output is false . The output is set even if an exception occurs during the attempt to acquire the lock. |
true
. true
if the current thread acquires the lock; otherwise, false
|
inlinestatic |
Releases the lock on an object and blocks the current thread until it reacquires the lock. If the specified time-out interval elapses, the thread enters the ready queue.
obj | The object on which to wait. |
milliseconds_timeout | The number of milliseconds to wait before the thread enters the ready queue. |
true
if the lock was reacquired before the specified time elapsed; false
if the lock was reacquired after the specified time elapsed. The method does not return until the lock is reacquired. xtd::threading::synchronization_lock_exception | xtd::threading::monitor::wait is not invoked from within a synchronized block of code. |
|
inlinestatic |
Releases the lock on an object and blocks the current thread until it reacquires the lock. If the specified time-out interval elapses, the thread enters the ready queue.
obj | The object on which to wait. |
timeout | A xtd::time_span representing the amount of time to wait before the thread enters the ready queue. |
true
if the lock was reacquired before the specified time elapsed; false
if the lock was reacquired after the specified time elapsed. The method does not return until the lock is reacquired. xtd::threading::synchronization_lock_exception | xtd::threading::monitor::wait is not invoked from within a synchronized block of code. |
|
inlinestatic |
Releases the lock on an object and blocks the current thread until it reacquires the lock.
obj | The object on which to wait. |
true
if the call returned because the caller reacquired the lock for the specified object. This method does not return if the lock is not reacquired. xtd::threading::synchronization_lock_exception | xtd::threading::monitor::wait is not invoked from within a synchronized block of code. |