From f421ec23ada99f2fd0c3d77e23e4faa01155e2fd Mon Sep 17 00:00:00 2001 From: Benjamin Walsh Date: Wed, 30 Nov 2016 17:41:16 -0500 Subject: [PATCH] kernel: fix race condition when spawning a thread with a delay Interrupt must be locked before inserting a timeout in the timeout queue. Change-Id: Iab0bf01f393e66a6403d2f85e899dbf737da4afc Signed-off-by: Benjamin Walsh --- kernel/unified/thread.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/unified/thread.c b/kernel/unified/thread.c index b2a14259db6..6862a1a99e9 100644 --- a/kernel/unified/thread.c +++ b/kernel/unified/thread.c @@ -221,8 +221,10 @@ static void schedule_new_thread(struct k_thread *thread, int32_t delay) start_thread(thread); } else { int32_t ticks = _TICK_ALIGN + _ms_to_ticks(delay); + int key = irq_lock(); _add_thread_timeout(thread, NULL, ticks); + irq_unlock(key); } #else ARG_UNUSED(delay);