diff --git a/kotlin-native/runtime/src/gc/cms/cpp/Barriers.cpp b/kotlin-native/runtime/src/gc/cms/cpp/Barriers.cpp index 29105fe5b2f..df747e4c143 100644 --- a/kotlin-native/runtime/src/gc/cms/cpp/Barriers.cpp +++ b/kotlin-native/runtime/src/gc/cms/cpp/Barriers.cpp @@ -187,13 +187,19 @@ ALWAYS_INLINE ObjHeader* gc::barriers::weakRefReadBarrier(std::atomic(gcHandle(), mm::SpecialRefRegistry::instance()); if (!terminateInSTW) { + // Mutator threads execute weak barrier in "native" state. This hack maes them stop with the rest of the world. + std::unique_lock markTerminationGuard(markTerminationMutex_); + stopTheWorld(gcHandle(), "GC stop the world #2: prepare to sweep"); }