In task_destroy(), if the task is not exclusively ours, then just use
task_kill(). If it is a shared task, then there is a race condition if
another thread tries to schedule it at the same time, which could result
in the task being scheduled after been freed.
This should be backported up to 2.8.
if (!t)
return;
+ if (t->tid != tid) {
+ task_kill(t);
+ return;
+ }
+
task_unlink_wq(t);
/* We don't have to explicitly remove from the run queue.
* If we are in the runqueue, the test below will set t->process