[K/N][Runtime] Separate thread registering and making it 'Runnable'
The new GC will require threads to suspend right after registering if Stop-The-World is requested. This patch changes the initial thread state to kNative and adds a separate state switch right after thread registering. This switch suspends if it is necessary.
This commit is contained in:
@@ -95,8 +95,13 @@ extern "C" MemoryState* InitMemory(bool firstRuntime) {
|
||||
}
|
||||
|
||||
extern "C" void DeinitMemory(MemoryState* state, bool destroyRuntime) {
|
||||
// We need the native state to avoid a deadlock on unregistering the thread.
|
||||
// The deadlock is possible if we are in the runnable state and the GC already locked
|
||||
// the thread registery and waits for threads to suspend or go to the native state.
|
||||
AssertThreadState(state, ThreadState::kNative);
|
||||
auto* node = mm::FromMemoryState(state);
|
||||
if (destroyRuntime) {
|
||||
ThreadStateGuard guard(state, ThreadState::kRunnable);
|
||||
node->Get()->gc().PerformFullGC();
|
||||
// TODO: Also make sure that finalizers are run.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user