Files
kotlin-fork/native/native.tests/testData/standalone/threadStates/callbackOnSeparateThread.kt
T
Vladimir Sukharev 5f51f5e1fc [K/N] Migrate more cinterop tests
^KT-61259
2024-01-16 11:58:31 +00:00

41 lines
1.0 KiB
Kotlin
Vendored

/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
// TARGET_BACKEND: NATIVE
// FREE_COMPILER_ARGS: -opt-in=kotlin.native.internal.InternalForKotlinNative
// MODULE: cinterop
// FILE: threadStates.def
language = C
---
void runInNewThread(void(*callback)(void));
// FILE: threadStates.cpp
#include <thread>
extern "C" void runInNewThread(void(*callback)(void)) {
std::thread t([callback]() {
callback();
});
t.join();
}
// MODULE: main(cinterop)
// FILE: main.kt
@file:OptIn(kotlin.native.runtime.NativeRuntimeApi::class, kotlinx.cinterop.ExperimentalForeignApi::class)
import kotlin.native.runtime.Debugging
import kotlin.test.*
import kotlinx.cinterop.*
import threadStates.*
fun main() {
runInNewThread(staticCFunction { ->
assertRunnableThreadState()
})
}
fun assertRunnableThreadState() {
assertTrue(Debugging.isThreadStateRunnable)
}