W3cubDocs

/Kotlin

Package kotlin.native.concurrent

Types

Platform and version requirements: Native (1.3)

AtomicInt

Atomic values and freezing: atomics AtomicInt, AtomicLong, AtomicNativePtr and AtomicReference are unique types with regard to freezing. Namely, they provide mutating operations, while can participate in frozen subgraphs. So shared frozen objects can have fields of atomic types.

class AtomicInt
Platform and version requirements: Native (1.3)

AtomicLong

class AtomicLong
Platform and version requirements: Native (1.3)

AtomicNativePtr

class AtomicNativePtr
Platform and version requirements: Native (1.3)

AtomicReference

An atomic reference to a frozen Kotlin object. Can be used in concurrent scenarious but frequently shall be of nullable type and be zeroed out once no longer needed. Otherwise memory leak could happen if the atomic reference is a part of a reference cycle.

class AtomicReference<T>
Platform and version requirements: Native (1.3)

Continuation0

class Continuation0 : () -> Unit
Platform and version requirements: Native (1.3)

Continuation1

class Continuation1<T1> : (T1) -> Unit
Platform and version requirements: Native (1.3)

Continuation2

class Continuation2<T1, T2> : (T1, T2) -> Unit
Platform and version requirements: Native (1.3)

DetachedObjectGraph

Detached object graph encapsulates transferrable detached subgraph which cannot be accessed externally, until it is attached with the attach extension function.

class DetachedObjectGraph<T>
Platform and version requirements: Native (1.3)

FreezableAtomicReference

An atomic reference to a Kotlin object. Can be used in concurrent scenarious, but must be frozen first, otherwise behaves as regular box for the value. If frozen, shall be zeroed out once no longer needed. Otherwise memory leak could happen if atomic reference is a part of a reference cycle.

class FreezableAtomicReference<T>
Platform and version requirements: Native (1.3)

FreezingException

Exception thrown whenever freezing is not possible.

class FreezingException : RuntimeException
Platform and version requirements: Native (1.3)

Future

Class representing abstract computation, whose result may become available in the future.

class Future<T>
Platform and version requirements: Native (1.3)

FutureState

State of the future object.

enum class FutureState
Platform and version requirements: Native (1.3)

InvalidMutabilityException

Exception thrown whenever we attempt to mutate frozen objects.

class InvalidMutabilityException : RuntimeException
Platform and version requirements: Native (1.3)

MutableData

Mutable concurrently accessible data buffer. Could be accessed from several workers simulteniously.

class MutableData
Platform and version requirements: Native (1.3)

TransferMode

Object Transfer Basics.

enum class TransferMode
Platform and version requirements: Native (1.3)

Worker

Class representing worker.

class Worker
Platform and version requirements: Native (1.3)

WorkerBoundReference

A frozen shared reference to a Kotlin object.

class WorkerBoundReference<out T : Any>

Annotations

Platform and version requirements: Native (1.0)

SharedImmutable

Marks a top level property with a backing field as immutable. It is possible to share the value of such property between multiple threads, but it becomes deeply frozen, so no changes can be made to its state or the state of objects it refers to.

annotation class SharedImmutable
Platform and version requirements: Native (1.0)

ThreadLocal

Marks a top level property with a backing field or an object as thread local. The object remains mutable and it is possible to change its state, but every thread will have a distinct copy of this object, so changes in one thread are not reflected in another.

annotation class ThreadLocal

Properties

Platform and version requirements: Native (1.3)

isFrozen

Checks if given object is null or frozen or permanent (i.e. instantiated at compile-time).

val Any?.isFrozen: Boolean

Functions

Platform and version requirements: Native (1.3)

atomicLazy

Atomic lazy initializer, could be used in frozen objects, freezes initializing lambda, so use very carefully. Also, as with other uses of an AtomicReference may potentially leak memory, so it is recommended to use atomicLazy in cases of objects living forever, such as object signletons, or in cases where it's guaranteed not to have cyclical garbage.

fun <T> atomicLazy(initializer: () -> T): Lazy<T>
Platform and version requirements: Native (1.3)

attach

Attaches previously detached object subgraph created by DetachedObjectGraph. Please note, that once object graph is attached, the DetachedObjectGraph.stable pointer does not make sense anymore, and shall be discarded, so attach of one DetachedObjectGraph object can only happen once.

fun <T> DetachedObjectGraph<T>.attach(): T
Platform and version requirements: Native (1.3)

callContinuation0

fun COpaquePointer.callContinuation0()
Platform and version requirements: Native (1.3)

callContinuation1

fun <T1> COpaquePointer.callContinuation1()
Platform and version requirements: Native (1.3)

callContinuation2

fun <T1, T2> COpaquePointer.callContinuation2()
Platform and version requirements: Native (1.3)

ensureNeverFrozen

This function ensures that if we see such an object during freezing attempt - freeze fails and FreezingException is thrown.

fun Any.ensureNeverFrozen()
Platform and version requirements: Native (1.3)

freeze

Freezes object subgraph reachable from this object. Frozen objects can be freely shared between threads/workers.

fun <T> T.freeze(): T
Platform and version requirements: Native (1.3)

waitForMultipleFutures

fun <T> Collection<Future<T>>.waitForMultipleFutures(
    millis: Int
): Set<Future<T>>
Platform and version requirements: Native (1.3)

withWorker

Executes block with new Worker as resource, by starting the new worker, calling provided block (in current context) with newly started worker as this and terminating worker after the block completes. Note that this operation is pretty heavyweight, use preconfigured worker or worker pool if need to execute it frequently.

fun <R> withWorker(
    name: String? = null, 
    errorReporting: Boolean = true, 
    block: Worker.() -> R
): R

© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.native.concurrent/index.html