[coop] Allow BLOCKING->DETACHED transition.
authorAleksey Kliger <aleksey@xamarin.com>
Wed, 4 May 2016 14:41:44 +0000 (10:41 -0400)
committerAleksey Kliger <aleksey@xamarin.com>
Wed, 4 May 2016 18:58:26 +0000 (14:58 -0400)
On coop, an OS thread can go
STARTING->BLOCKING->RUNNING->BLOCKING->DETACHED.

For ordinary managed threads BLOCKING->DETACHED is still a bug like
before, but hopefully the checked build machinery will help us to catch
those situations.

mono/utils/mono-threads-state-machine.c

index 32491a4ca225229e622799504f8d7cc6012c031c..7882f1f0fdf632e67a6a8d26adcdbc7a8bf4b4a5 100644 (file)
@@ -133,6 +133,7 @@ retry_state_change:
        UNWRAP_THREAD_STATE (raw_state, cur_state, suspend_count, info);
        switch (cur_state) {
        case STATE_RUNNING:
+       case STATE_BLOCKING: /* An OS thread on coop goes STARTING->BLOCKING->RUNNING->BLOCKING->DETACHED */
                g_assert (suspend_count == 0);
                if (InterlockedCompareExchange (&info->thread_state, STATE_DETACHED, raw_state) != raw_state)
                        goto retry_state_change;
@@ -140,11 +141,11 @@ retry_state_change:
                return TRUE;
        case STATE_ASYNC_SUSPEND_REQUESTED: //Can't detach until whoever asked us to suspend to be happy with us
                return FALSE;
+
 /*
 STATE_ASYNC_SUSPENDED: Code should not be running while suspended.
 STATE_SELF_SUSPENDED: Code should not be running while suspended.
 STATE_SELF_SUSPEND_REQUESTED: This is a bug in the self suspend code that didn't execute the second part of it
-STATE_BLOCKING: This is a bug in the coop code that forgot to do a finish blocking before exiting.
 STATE_BLOCKING_AND_SUSPENDED: This is a bug in coop x suspend that resulted the thread in an undetachable state.
 */
        default: