pthread: Properly change state for running threads
authorBarret Rhoden <brho@cs.berkeley.edu>
Tue, 20 Oct 2015 18:56:49 +0000 (14:56 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Wed, 28 Oct 2015 16:05:13 +0000 (12:05 -0400)
We were only setting PTH_RUNNING for thread 0 early on.  After that, it
was all PTH_RUNNABLES.  We should now be able to assert that if a thread
is on the active list, it is marked PTH_RUNNING.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
user/pthread/pthread.c

index 59cf4cb..ec9a646 100644 (file)
@@ -221,6 +221,8 @@ static void __attribute__((noreturn)) pth_sched_entry(void)
                new_thread = TAILQ_FIRST(&ready_queue);
                if (new_thread) {
                        TAILQ_REMOVE(&ready_queue, new_thread, tq_next);
+                       assert(new_thread->state == PTH_RUNNABLE);
+                       new_thread->state = PTH_RUNNING;
                        TAILQ_INSERT_TAIL(&active_queue, new_thread, tq_next);
                        threads_active++;
                        threads_ready--;
@@ -243,7 +245,6 @@ static void __attribute__((noreturn)) pth_sched_entry(void)
                if (!parlib_wants_to_be_mcp)
                        sys_yield(FALSE);
        } while (1);
-       assert(new_thread->state == PTH_RUNNABLE);
        /* Prep the pthread to run any pending posix signal handlers registered
      * via pthread_kill once it is restored. */
        __pthread_prep_for_pending_posix_signals(new_thread);