shadow:natives

Class ConditionVariable

Parent class

shadow:standard@Object

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.

Author

Barry Wittman

See Also

Create Summary

Modifiers Return Types Method and Description
public () create()

Initializes a new ConditionVariable.

Destroy Summary

Modifiers Return Types Method and Description
public () destroy()

Method Summary

Modifiers Return Types Method and Description
public readonly (ConditionVariable) copy(AddressMap addresses)
public readonly locked () free()

Frees the resources allocated by this ConditionVariable.

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 notifyAll() on this condition variable or interrupt() on the calling thread.

public readonly locked (boolean) wait(int milliseconds)

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.

public readonly locked (boolean) wait(TimeSpan timeout)

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.

Create Detail

create

public create() => ()

Initializes a new ConditionVariable.

Destroy Detail

destroy

public destroy() => ()

Method Detail

copy

public readonly copy(AddressMap addresses) => (ConditionVariable)

free

public readonly locked free() => ()

Frees the resources allocated by this ConditionVariable.

Throws

ConditionVariableException - if the mutex associated with the condition variable is locked by another thread.

lock

public readonly locked lock() => ()

Attempts to lock the mutex associated with the condition variable.

Throws

FreedResourceException - if the condition variable has been freed.

notifyAll

public readonly locked notifyAll() => ()

Wakes up all the waiting threads. The mutex associated with the condition variable must not be locked when this happens.

Throws

FreedResourceException - if the condition variable has been freed.

unlock

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.

Throws

ConditionVariableException - if the mutex is not owned by this thread.

FreedResourceException - if the condition variable has been freed.

wait

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.

wait

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.

Parameters

milliseconds - The amount of time to wait, in milliseconds, before timing out.

Returns

false if the operation timed-out, otherwise true.

Throws

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.

wait

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.

Parameters

timeout - The amount of time to wait, expressed as a TimeSpan, before timing out.

Returns

false if the operation timed-out, otherwise true.

Throws

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.