- ret = mono_threads_get_runtime_callbacks ()->thread_state_init_from_sigctx (¤t->thread_saved_state [ASYNC_SUSPEND_STATE_INDEX], context);
-
- /* thread_state_init_from_sigctx return FALSE if the current thread is detaching and suspend can't continue. */
- current->suspend_can_continue = ret;
+ /*
+ * If the thread is starting, then thread_state_init_from_sigctx returns FALSE,
+ * as the thread might have been attached without the domain or lmf having been
+ * initialized yet.
+ *
+ * One way to fix that is to keep the thread suspended (wait for the restart
+ * signal), and make sgen aware that even if a thread might be suspended, there
+ * would be cases where you cannot scan its stack/registers. That would in fact
+ * consist in removing the async suspend compensation, and treat the case directly
+ * in sgen. That's also how it was done in the sgen specific suspend code.
+ */
+
+ /* thread_state_init_from_sigctx return FALSE if the current thread is starting or detaching and suspend can't continue. */
+ current->suspend_can_continue = mono_threads_get_runtime_callbacks ()->thread_state_init_from_sigctx (¤t->thread_saved_state [ASYNC_SUSPEND_STATE_INDEX], context);
+
+ if (!current->suspend_can_continue)
+ THREADS_SUSPEND_DEBUG ("\tThread is starting or detaching, failed to capture state %p\n", mono_thread_info_get_tid (current));