[K/N] Fix possible data races found by thread sanitizer

This commit is contained in:
Pavel Kunyavskiy
2022-07-27 15:47:34 +02:00
committed by Space
parent 828811a47f
commit 18cda8844d
21 changed files with 267 additions and 122 deletions
@@ -0,0 +1,41 @@
// 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.*
val sem = AtomicInt(0)
fun box() : String {
val w1 = Worker.start()
val w2 = Worker.start()
val f1 = w1.execute(
mode = TransferMode.SAFE,
{ },
{
sem.increment();
while (sem.value != 3) {}
O
}
)
val f2 = w2.execute(
mode = TransferMode.SAFE,
{ },
{
sem.increment();
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
}