CSProducerConsumerData

class CSProducerConsumerData<T : Any>(initial: () -> T)

A thread-safe data structure for producer-consumer scenarios.

It maintains two versions of data: an 'active' one for consumers and a 'prepared' one for the producer. The producer can prepare new data in the background. The swap() method then atomically makes the prepared data active for consumers.

Type Parameters

T

The type of data being managed.

Constructors

Link copied to clipboard
constructor(initial: () -> T)

Properties

Link copied to clipboard
val active: T
Link copied to clipboard
val prepared: T

Functions

Link copied to clipboard
fun clear()
Link copied to clipboard
fun prepare(value: T)
Link copied to clipboard
fun swap()