From 4c2fc2aed7c7d279f867a574c0459295b35ee029 Mon Sep 17 00:00:00 2001 From: Andy Ross Date: Fri, 17 Jan 2020 10:43:26 -0800 Subject: [PATCH] kernel/queue: Fix SMP race Calling z_ready_thread() means the thread is now ready and can wake up at any moment on another CPU. But we weren't finished setting the return value! So the other side could wake up with a spurious "error" condition if it ran too soon. Note that on systems with a working IPI, that wakeup can happen much faster than you might think. Signed-off-by: Andy Ross --- kernel/queue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/queue.c b/kernel/queue.c index 6abd4a30ee3..329a281edf3 100644 --- a/kernel/queue.c +++ b/kernel/queue.c @@ -103,8 +103,8 @@ static inline void z_vrfy_k_queue_init(struct k_queue *queue) #if !defined(CONFIG_POLL) static void prepare_thread_to_run(struct k_thread *thread, void *data) { - z_ready_thread(thread); z_thread_return_value_set_with_data(thread, 0, data); + z_ready_thread(thread); } #endif /* CONFIG_POLL */