Skip to content

Commit

Permalink
samples/synchronization: fix thread b pinning
Browse files Browse the repository at this point in the history
This commit adds a brief thread b suspend while the sample sets its
affinity mask.

If the call to `k_thread_cpu_pin` is being made while the thread is
actively running, then we get `-EINVAL` and the affinity mask is left
unchanged.

Signed-off-by: Filip Kokosinski <[email protected]>
  • Loading branch information
fkokosinski authored and fabiobaltieri committed Jul 30, 2024
1 parent 39a70be commit 81cb80d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions samples/synchronization/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,16 @@ int main(void)
#if PIN_THREADS
if (arch_num_cpus() > 1) {
k_thread_cpu_pin(&thread_a_data, 0);

/*
* Thread b is a static thread that is spawned immediately. This means that the
* following `k_thread_cpu_pin` call can fail with `-EINVAL` if the thread is
* actively running. Let's suspend the thread and resume it after the affinity mask
* is set.
*/
k_thread_suspend(thread_b);
k_thread_cpu_pin(thread_b, 1);
k_thread_resume(thread_b);
}
#endif

Expand Down

0 comments on commit 81cb80d

Please sign in to comment.