ConditionVariable


@UnstableApi
class ConditionVariable


An interruptible condition variable. This class provides a number of benefits over :

Summary

Public constructors

Creates a closed instance using DEFAULT.

Creates an instance, which starts closed.

Public functions

synchronized Unit

Blocks until the condition is opened.

synchronized Boolean
block(timeoutMs: Long)

Blocks until the condition is opened or until timeoutMs have passed.

synchronized Unit

Blocks until the condition is open.

synchronized Boolean

Closes the condition.

synchronized Boolean

Opens the condition and releases all threads that are blocked.

Public properties

Boolean

Public constructors

ConditionVariable

ConditionVariable()

Creates a closed instance using DEFAULT.

ConditionVariable

ConditionVariable(clock: Clock!)

Creates an instance, which starts closed.

Parameters
clock: Clock!

The Clock whose elapsedRealtime method is used to determine when block should time out.

Public functions

block

synchronized fun block(): Unit

Blocks until the condition is opened.

Throws
java.lang.InterruptedException

If the thread is interrupted.

block

synchronized fun block(timeoutMs: Long): Boolean

Blocks until the condition is opened or until timeoutMs have passed.

Parameters
timeoutMs: Long

The maximum time to wait in milliseconds. If timeoutMs <= 0 then the call will return immediately without blocking.

Returns
Boolean

True if the condition was opened, false if the call returns because of the timeout.

Throws
java.lang.InterruptedException

If the thread is interrupted.

blockUninterruptible

synchronized fun blockUninterruptible(): Unit

Blocks until the condition is open. Unlike block, this method will continue to block if the calling thread is interrupted. If the calling thread was interrupted then its interrupted status will be set when the method returns.

close

synchronized fun close(): Boolean

Closes the condition.

Returns
Boolean

True if the condition variable was closed. False if it was already closed.

open

synchronized fun open(): Boolean

Opens the condition and releases all threads that are blocked.

Returns
Boolean

True if the condition variable was opened. False if it was already open.

Public properties

isOpen

val isOpenBoolean