Package kotlin.concurrent

Utility functions for concurrent programming.

Types

Native
1.9

AtomicArray

An Array in which elements are always updated atomically. For additional details about atomicity guarantees for reads and writes see kotlin.concurrent.Volatile.

class AtomicArray<T>
Native
1.9

AtomicInt

An Int value that is always updated atomically. For additional details about atomicity guarantees for reads and writes see kotlin.concurrent.Volatile.

class AtomicInt
Native
1.9

AtomicIntArray

An IntArray in which elements are always updated atomically. For additional details about atomicity guarantees for reads and writes see kotlin.concurrent.Volatile.

class AtomicIntArray
Native
1.9

AtomicLong

A Long value that is always updated atomically. For additional details about atomicity guarantees for reads and writes see kotlin.concurrent.Volatile.

class AtomicLong
Native
1.9

AtomicLongArray

An LongArray in which elements are always updated atomically. For additional details about atomicity guarantees for reads and writes see kotlin.concurrent.Volatile.

class AtomicLongArray
Native
1.9

AtomicNativePtr

A kotlinx.cinterop.NativePtr value that is always updated atomically. For additional details about atomicity guarantees for reads and writes see kotlin.concurrent.Volatile.

class AtomicNativePtr
Native
1.9

AtomicReference

An object reference that is always updated atomically.

class AtomicReference<T>

Annotations

Volatile

Marks the backing field of the annotated var property as volatile, meaning that reads and writes to this field are atomic and writes are always made visible to other threads. If another thread reads the value of this field (e.g. through its accessor), it sees not only that value, but all side effects that led to writing that value.

Common
Native
1.9
annotation class Volatile
JVM
1.9
typealias Volatile = Volatile

Extensions for External Classes

Functions

Native
1.9

AtomicArray

Creates a new AtomicArray of the given size, where each element is initialized by calling the given init function.

fun <T> AtomicArray(
    size: Int,
    init: (Int) -> T
): AtomicArray<T>
Native
1.9

AtomicIntArray

Creates a new AtomicIntArray of the given size, where each element is initialized by calling the given init function.

fun AtomicIntArray(
    size: Int,
    init: (Int) -> Int
): AtomicIntArray
Native
1.9

AtomicLongArray

Creates a new AtomicLongArray of the given size, where each element is initialized by calling the given init function.

fun AtomicLongArray(
    size: Int,
    init: (Int) -> Long
): AtomicLongArray
JVM
1.0

fixedRateTimer

Creates a timer that executes the specified action periodically, starting after the specified initialDelay (expressed in milliseconds) and with the interval of period milliseconds between the start of the previous task and the start of the next one.

fun fixedRateTimer(
    name: String? = null,
    daemon: Boolean = false,
    initialDelay: Long = 0.toLong(),
    period: Long,
    action: TimerTask.() -> Unit
): Timer

Creates a timer that executes the specified action periodically, starting at the specified startAt date and with the interval of period milliseconds between the start of the previous task and the start of the next one.

fun fixedRateTimer(
    name: String? = null,
    daemon: Boolean = false,
    startAt: Date,
    period: Long,
    action: TimerTask.() -> Unit
): Timer
JVM
1.0

thread

Creates a thread that runs the specified block of code.

fun thread(
    start: Boolean = true,
    isDaemon: Boolean = false,
    contextClassLoader: ClassLoader? = null,
    name: String? = null,
    priority: Int = -1,
    block: () -> Unit
): Thread
JVM
1.0

timer

Creates a timer that executes the specified action periodically, starting after the specified initialDelay (expressed in milliseconds) and with the interval of period milliseconds between the end of the previous task and the start of the next one.

fun timer(
    name: String? = null,
    daemon: Boolean = false,
    initialDelay: Long = 0.toLong(),
    period: Long,
    action: TimerTask.() -> Unit
): Timer

Creates a timer that executes the specified action periodically, starting at the specified startAt date and with the interval of period milliseconds between the end of the previous task and the start of the next one.

fun timer(
    name: String? = null,
    daemon: Boolean = false,
    startAt: Date,
    period: Long,
    action: TimerTask.() -> Unit
): Timer
JVM
1.0

timerTask

Wraps the specified action in a TimerTask.

fun timerTask(action: TimerTask.() -> Unit): TimerTask