Module: xenomai-3
Branch: next
Commit: cc4ecb09efd530248d11910db1626d83bbb143b8

Author: Philippe Gerum <>
Date:   Tue May 16 11:12:57 2017 +0200

lib/copperplate: prevent unwanted mode switch during thread prologue

copperplate_renice_local_thread() causes a switch to secondary mode
for an emerging thread context, we want it to happen before such
thread handshakes with its parent, so that the later is released only
after the child is waiting in primary mode on the start barrier.


tA(prio=10) creates tB(prio=5), tC(prio=7), then starts them in that
order. The proper scheduling sequence must be: tA -> tC -> tB.

See for more


 lib/copperplate/internal.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/copperplate/internal.c b/lib/copperplate/internal.c
index 2549ab0..1d96526 100644
--- a/lib/copperplate/internal.c
+++ b/lib/copperplate/internal.c
@@ -239,14 +239,14 @@ static void *thread_trampoline(void *arg)
         * with the cleanup code the client may run whenever
         * copperplate_create_thread() fails.
-       prepare_wait_corespec();
-       __RT(sem_post(&cta->__reserved.warm));
-       thread_spawn_wait(&released);
-       __RT(sem_destroy(&released));
        ret = __bt(copperplate_renice_local_thread(pthread_self(),
                           _cta.policy, &_cta.param_ex));
        if (ret)
                warning("cannot renice core thread, %s", symerror(ret));
+       prepare_wait_corespec();
+       __RT(sem_post(&cta->__reserved.warm));
+       thread_spawn_wait(&released);
+       __RT(sem_destroy(&released));

Xenomai-git mailing list

Reply via email to