Just do the `(tcb_t*) sched_threads[pid];` assignment here (inside the the critical section of course) and test `sched_kill_thread == NULL` in the if-condition.