With this patch, if handle_incoming_wakeups() discovers in a CPU's wakeup
queue a thread which does not actually belong to it, it simply ignores it.

This case should never happen. However, in a following patch we add the
ability to pin (migrate) a waiting thread, and that operating might race
with a wake() of the same thread, resulting in the thread remaining on
the old cpu's wakeup queues, and we better ignore it there.

Signed-off-by: Nadav Har'El <[email protected]>
---
 core/sched.cc | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/core/sched.cc b/core/sched.cc
index 7a4afeb..0507d2c 100644
--- a/core/sched.cc
+++ b/core/sched.cc
@@ -442,6 +442,9 @@ void cpu::handle_incoming_wakeups()
                     // Special case of current thread being woken before
                     // having a chance to be scheduled out.
                     t._detached_state->st.store(thread::status::running);
+                } else if (t.tcpu() != this) {
+                    // Thread was woken on the wrong cpu. Can be a side-effect
+                    // of sched::thread::pin(thread*, cpu*). Do nothing.
                 } else {
                     t._detached_state->st.store(thread::status::queued);
                     // Make sure the CPU-local runtime measure is suitably
-- 
2.5.5

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to