From 31036f1dc8a963fb0bc3fc103f63028988314fea Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Mon, 18 Jul 2022 09:41:39 +0200 Subject: score: Use priority inheritance for thread join Threads may join the thread termination of another thread using the pthread_join() or rtems_task_delete() directives. The thread cancel operation used a special case priority boosting mechanism implemented by _Thread_Raise_real_priority(). The problem was that this approach * is not transitive, * does not account for priority adjustments of the calling task while waiting for the join, * does not support clustered scheduling, and * does not detect deadlocks. All these problems are fixed by using a priority inheritance thread queue for the join operation. Close #4679. --- testsuites/smptests/smppsxmutex01/init.c | 33 ++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'testsuites/smptests') diff --git a/testsuites/smptests/smppsxmutex01/init.c b/testsuites/smptests/smppsxmutex01/init.c index f5aacb42d8..0022e81b5f 100644 --- a/testsuites/smptests/smppsxmutex01/init.c +++ b/testsuites/smptests/smppsxmutex01/init.c @@ -55,25 +55,11 @@ static test_context test_instance; static void *thread_b(void *arg) { test_context *ctx; - rtems_id scheduler_b_id; - rtems_status_code sc; - rtems_task_priority prio; int prio_ceiling; int eno; ctx = arg; - rtems_test_assert(rtems_scheduler_get_processor() == 0); - - sc = rtems_scheduler_ident(SCHED_B, &scheduler_b_id); - rtems_test_assert(sc == RTEMS_SUCCESSFUL); - - sc = rtems_task_set_priority(pthread_self(), RTEMS_CURRENT_PRIORITY, &prio); - rtems_test_assert(sc == RTEMS_SUCCESSFUL); - - sc = rtems_task_set_scheduler(pthread_self(), scheduler_b_id, prio); - rtems_test_assert(sc == RTEMS_SUCCESSFUL); - rtems_test_assert(rtems_scheduler_get_processor() == 1); eno = pthread_mutex_init(&ctx->mtx_b, &ctx->mtx_attr); @@ -132,8 +118,24 @@ static void test(test_context *ctx) rtems_test_assert(eno == 0); if (cpu_count > 1) { + rtems_id scheduler_a_id; + rtems_id scheduler_b_id; + rtems_status_code sc; + rtems_task_priority prio; void *exit_code; + sc = rtems_scheduler_ident(SCHED_A, &scheduler_a_id); + rtems_test_assert(sc == RTEMS_SUCCESSFUL); + + sc = rtems_scheduler_ident(SCHED_B, &scheduler_b_id); + rtems_test_assert(sc == RTEMS_SUCCESSFUL); + + sc = rtems_task_set_priority(pthread_self(), RTEMS_CURRENT_PRIORITY, &prio); + rtems_test_assert(sc == RTEMS_SUCCESSFUL); + + sc = rtems_task_set_scheduler(pthread_self(), scheduler_b_id, prio); + rtems_test_assert(sc == RTEMS_SUCCESSFUL); + eno = pthread_create(&ctx->thread_b, NULL, thread_b, ctx); rtems_test_assert(eno == 0); @@ -141,6 +143,9 @@ static void test(test_context *ctx) eno = pthread_join(ctx->thread_b, &exit_code); rtems_test_assert(eno == 0); rtems_test_assert(exit_code == ctx); + + sc = rtems_task_set_scheduler(pthread_self(), scheduler_a_id, prio); + rtems_test_assert(sc == RTEMS_SUCCESSFUL); } eno = pthread_mutex_destroy(&ctx->mtx_a); -- cgit v1.2.3