immutable locked class ConditionVariable
Class ConditionVariable
is an implementation of a condition variable in Shadow. A condition variable is used to wait for a specific condition to be true. It has a built-in lock (mutex) that must be acquired before the condition can be checked. If the condition isn't true, a wait()
method can be called, which automatically releases the lock. Other threads can call notifyAll()
to wake up threads so that they can check to see if the condition is still false before calling wait()
again. Unlike Mutex
, a ConditionVariable
can only be locked once by a given thread.
Barry Wittman
Modifiers | Return Types | Method and Description |
---|---|---|
public |
() |
create() Initializes a new |
Modifiers | Return Types | Method and Description |
---|---|---|
public |
() |
destroy() |
Modifiers | Return Types | Method and Description |
---|---|---|
public readonly |
(ConditionVariable) |
copy(AddressMap addresses) |
public readonly locked |
() |
free() Frees the resources allocated by this |
public readonly locked |
() |
lock() Attempts to lock the mutex associated with the condition variable. |
public readonly locked |
() |
notifyAll() Wakes up all the waiting threads. |
public readonly locked |
() |
unlock() Attempts to unlock the mutex associated with the condition variable. |
public readonly locked |
() |
wait() Suspends the calling thread until another thread calls |
public readonly locked |
(boolean) |
wait(int milliseconds) Suspends the calling thread until another thread calls |
public readonly locked |
(boolean) |
wait(TimeSpan timeout) Suspends the calling thread until another thread calls |
public create() => ()
Initializes a new ConditionVariable
.
public destroy() => ()
public readonly copy(AddressMap addresses) => (ConditionVariable)
public readonly locked free() => ()
Frees the resources allocated by this ConditionVariable
.
ConditionVariableException
- if the mutex associated with the condition variable is locked by another thread.
public readonly locked lock() => ()
Attempts to lock the mutex associated with the condition variable.
FreedResourceException
- if the condition variable has been freed.
public readonly locked notifyAll() => ()
Wakes up all the waiting threads. The mutex associated with the condition variable must not be locked when this happens.
FreedResourceException
- if the condition variable has been freed.
public readonly locked unlock() => ()
Attempts to unlock the mutex associated with the condition variable. If the mutex has been locked multiple times by this thread, this method simply decreases the counter. The mutex is unlocked when an corresponding unlock has been called for each lock, e.g. if lock()
was called twice, unlock()
will unlock the mutex on its second call.
ConditionVariableException
- if the mutex is not owned by this thread.
FreedResourceException
- if the condition variable has been freed.
public readonly locked wait() => ()
Suspends the calling thread until another thread calls notifyAll()
on this condition variable or interrupt()
on the calling thread. The mutex associated with this condition variable must already be locked by the calling thread.
public readonly locked wait(int milliseconds) => (boolean)
Suspends the calling thread until another thread calls notifyAll()
on this condition variable or interrupt()
on the calling thread, or the specified amount of time elapses. The mutex associated with this condition variable must already be locked by the calling thread.
milliseconds
- The amount of time to wait, in milliseconds, before timing out.
false
if the operation timed-out, otherwise true
.
FreedResourceException
- if the condition variable has been freed.
InterruptedException
- if another thread requested to interrupt this thread.
ConditionVariableException
- if the thread does not own the mutex associated with the condition variable.
public readonly locked wait(TimeSpan timeout) => (boolean)
Suspends the calling thread until another thread calls notifyAll()
on this condition variable or interrupt()
on the calling thread, or the specified amount of time elapses. The mutex associated with this condition variable must already be locked by the calling thread.
timeout
- The amount of time to wait, expressed as a TimeSpan, before timing out.
false
if the operation timed-out, otherwise true
.
FreedResourceException
- if the condition variable has been freed.
InterruptedException
- if another thread requested to interrupt this thread.
ConditionVariableException
- if the thread does not own the mutex associated with the condition variable.