From 692bac22f5a39510ba8220c72a8f1e8c471e4643 Mon Sep 17 00:00:00 2001 From: Peter Bigot Date: Mon, 8 Mar 2021 08:30:47 -0600 Subject: [PATCH] tests: footprint: fix thread start races The test granted access to the user work queue stack from the user work thread; this was done by k_work_user_queue_start() so was unnecessary. Document why it's ok to grant other access after the work thread was started. Fix a race condition where the non-work user thread might have started before it was given access to the resources it needs. Signed-off-by: Peter Bigot --- tests/benchmarks/footprints/src/workq.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/benchmarks/footprints/src/workq.c b/tests/benchmarks/footprints/src/workq.c index ef15d12b65c..a3c86a420cc 100644 --- a/tests/benchmarks/footprints/src/workq.c +++ b/tests/benchmarks/footprints/src/workq.c @@ -111,13 +111,16 @@ void run_workq(void) K_THREAD_STACK_SIZEOF(user_workq_stack), CONFIG_MAIN_THREAD_PRIORITY, NULL); + /* The work queue thread has been started, but it's OK because + * it doesn't need these permissions until something's submitted + * to it. + */ k_mem_domain_add_thread(&footprint_mem_domain, &user_workq.thread); - k_thread_access_grant(&user_workq.thread, &user_workq_stack); k_thread_access_grant(&user_workq.thread, &sync_sema); tid = k_thread_create(&my_thread, my_stack_area, STACK_SIZE, simple_user_workq_thread, NULL, NULL, NULL, - 0, K_USER, K_NO_WAIT); + 0, K_USER, K_FOREVER); k_thread_access_grant(tid, &sync_sema, &user_workq.thread, &user_workq.queue,