diff --git a/kotlin-native/runtime/src/mm/cpp/ThreadSuspension.cpp b/kotlin-native/runtime/src/mm/cpp/ThreadSuspension.cpp index 701e9bd495f..738a637a934 100644 --- a/kotlin-native/runtime/src/mm/cpp/ThreadSuspension.cpp +++ b/kotlin-native/runtime/src/mm/cpp/ThreadSuspension.cpp @@ -22,7 +22,9 @@ bool isSuspendedOrNative(kotlin::mm::ThreadData& thread) noexcept { template bool allThreads(F predicate) noexcept { auto& threadRegistry = kotlin::mm::ThreadRegistry::Instance(); - auto* currentThread = threadRegistry.CurrentThreadData(); + auto* currentThread = (threadRegistry.IsCurrentThreadRegistered()) + ? threadRegistry.CurrentThreadData() + : nullptr; kotlin::mm::ThreadRegistry::Iterable threads = kotlin::mm::ThreadRegistry::Instance().LockForIter(); for (auto& thread : threads) { // Handle if suspension was initiated by the mutator thread.