sched.c: make sched_task_kill atomic

Also move deletion of active thread and context switching into
thread_task_kill with appropriate check.