75b4469757
`AtomicInt`, `AtomicLong`, `AtomicReference` and `AtomicNativePtr` classes were moved to `kotlin.concurrent` package. The corresponding classes from `kotlin.native.concurrent` were deprecated with warning since Kotlin 1.9.
In order to prepare for further commonization of Atomics API the following changes were made:
* `kotlin.concurrent.AtomicInt`:
* `increment(): Unit` and `decrement(): Unit` methods were deprecated with error
* New methods were added: `incrementAndGet(): Int` , `decrementAndGet(): Int`, `getAndIncrement(): Int`, `getAndDecrement(): Int`, `getAndSet(newValue: Int): Int`
* `kotlin.concurrent.AtomicLong`:
* `increment(): Unit` and `decrement(): Unit` methods were deprecated with error
* New methods were added: `incrementAndGet(): Long`, `decrementAndGet(): Long`, `getAndIncrement(): Long`, `getAndDecrement(): Long`, `getAndSet(newValue: Long): Long`
* Deprecated `AtomicLong()` constructor with default parameter value
* For all atomic classes `compareAndSwap` method was renamed to `compareAndExchange`
See KT-58074 for more details.
Merge-request: KT-MR-9272
Merged-by: Maria Sokolova <maria.sokolova@jetbrains.com>
43 lines
887 B
Kotlin
Vendored
43 lines
887 B
Kotlin
Vendored
// TARGET_BACKEND: NATIVE
|
|
|
|
// FILE: 1.kt
|
|
|
|
val O = if (true) "O" else "F" // to avoid const init
|
|
val K = if (true) "K" else "A" // to avoid const init
|
|
|
|
// FILE: main.kt
|
|
|
|
import kotlin.native.concurrent.*
|
|
import kotlin.concurrent.AtomicInt
|
|
|
|
val sem = AtomicInt(0)
|
|
|
|
fun box() : String {
|
|
val w1 = Worker.start()
|
|
val w2 = Worker.start()
|
|
val f1 = w1.execute(
|
|
mode = TransferMode.SAFE,
|
|
{ },
|
|
{
|
|
sem.incrementAndGet();
|
|
while (sem.value != 3) {}
|
|
O
|
|
}
|
|
)
|
|
val f2 = w2.execute(
|
|
mode = TransferMode.SAFE,
|
|
{ },
|
|
{
|
|
sem.incrementAndGet();
|
|
while (sem.value != 3) {}
|
|
K
|
|
}
|
|
)
|
|
while (sem.value != 2) {}
|
|
sem.value = 3
|
|
val result = f1.result + f2.result
|
|
w1.requestTermination().result
|
|
w2.requestTermination().result
|
|
return result
|
|
}
|