Notifies a thread in the waiting queue of a change in the locked object's state.
public:
static void Pulse(System::Object ^ obj);
public static void Pulse(object obj);
static member Pulse : obj -> unit
Public Shared Sub Pulse (obj As Object)
Parameters
The object a thread is waiting for.
ExceptionsThe obj
parameter is null
.
The calling thread does not own the lock for the specified object.
RemarksOnly the current owner of the lock can signal a waiting object using Pulse
.
The thread that currently owns the lock on the specified object invokes this method to signal the next thread in line for the lock. Upon receiving the pulse, the waiting thread is moved to the ready queue. When the thread that invoked Pulse
releases the lock, the next thread in the ready queue (which is not necessarily the thread that was pulsed) acquires the lock.
Important
The Monitor class does not maintain state indicating that the Pulse method has been called. Thus, if you call Pulse when no threads are waiting, the next thread that calls Wait blocks as if Pulse had never been called. If two threads are using Pulse and Wait to interact, this could result in a deadlock. Contrast this with the behavior of the AutoResetEvent class: If you signal an AutoResetEvent by calling its Set method, and there are no threads waiting, the AutoResetEvent remains in a signaled state until a thread calls WaitOne, WaitAny, or WaitAll. The AutoResetEvent releases that thread and returns to the unsignaled state.
Note that a synchronized object holds several references, including a reference to the thread that currently holds the lock, a reference to the ready queue, which contains the threads that are ready to obtain the lock, and a reference to the waiting queue, which contains the threads that are waiting for notification of a change in the object's state.
The Pulse
, PulseAll, and Wait methods must be invoked from within a synchronized block of code.
To signal multiple threads, use the PulseAll method.
See alsoCollaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide. In this articleWas this page helpful?
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4