[Xenomai] The task calling pthread_cond_signal() has to own the lock

Giulio Moro g.moro at qmul.ac.uk
Mon Oct 2 16:08:54 CEST 2017


I am using condition variables with the Posix skin on Xenomai 3.0.5
I find that if the thread calling pthread_cond_signal() has not acquired the lock associated with the condition variable, the waiting thread is not resumed. Is this expected behaviour? As
According to the Posix specifications (referenced by the Xenomai docs):
"The pthread_cond_broadcast() or pthread_cond_signal() functions may be called by a thread whether or not it currently owns the mutex that threads calling pthread_cond_wait() or pthread_cond_timedwait() "
therefore, I think that what I observe is unexpected behaviour.
Note: I am happy for my use case to accept the non-deterministic behaviour caused by the signalling thread not acquiring the lock.

My test code is here: https://pastebin.com/raw/zjmQBFxr

If I #define SIGNALLER_ACQUIRES_LOCK, then main() acquires mutex before calling pthread_cond_signal() and the waiting thread is successfully resumed.
The program therefore prints:
main(): Signalling condition
callback(): start
callback(): Locking mutex
callback(): Waiting on condition
main(): Signalling condition
callback(): Unlocking mutex
callback(): Locking mutex
callback(): Waiting on condition
....

However, if I do not define the macro, then the waiting thread is never resumed, here is the printout:
main(): Signalling condition
callback(): start
callback(): Locking mutex
callback(): Waiting on condition
main(): Signalling condition
main(): Signalling condition
main(): Signalling condition
main(): Signalling condition
main(): Signalling condition
....

I am compiling with:
clang test-xeno-cond.c `/usr/xenomai/bin/xeno-config --skin=posix --cflags --ldflags` -o cond

and `/usr/xenomai/bin/xeno-config --skin=posix --cflags --ldflags` returns:
-I/usr/xenomai/include/cobalt -I/usr/xenomai/include -march=armv7-a -mfpu=vfp3 -D_GNU_SOURCE -D_REENTRANT -D__COBALT__ -D__COBALT_WRAP__
-Wl,--no-as-needed -Wl,@/usr/xenomai/lib/cobalt.wrappers -Wl,@/usr/xenomai/lib/modechk.wrappers  /usr/xenomai/lib/xenomai/bootstrap.o -Wl,--wrap=main -Wl,--dynamic-list=/usr/xenomai/lib/dynlist.ld -L/usr/xenomai/lib -lcobalt -lmodechk -lpthread -lrt



More information about the Xenomai mailing list