[Xenomai] pthread_rt and C++ on Xenomai 2.6

Giulio Moro giuliomoro at yahoo.it
Sun Feb 19 02:38:13 CET 2017


What's the deal with using the posix skin to wrap C++ mutex, locks and threads?
I am on ARMv7 (Beaglebone Black), with gcc 4.9, xeno-config on this system returns the following:$ /usr/xenomai/bin/xeno-config --skin=posix --ldflags --cflags-Wl,@/usr/xenomai/lib/posix.wrappers -L/usr/xenomai/lib -lpthread_rt -lxenomai -lpthread -lrt-I/usr/xenomai/include -D_GNU_SOURCE -D_REENTRANT -D__XENO__ -I/usr/xenomai/include/posix
The example code here http://www.cplusplus.com/reference/mutex/mutex/try_lock/
compiles and runs fine (i.e.: I get a reasonable number of increases of the counter) with (1) g++ -pthread test.cpp -std=c++14 -lpthread

but if I wrap the posix calls with(2) gcc test.cpp -std=c++14  -I/usr/xenomai/include -D_GNU_SOURCE -D_REENTRANT -D__XENO__ -I/usr/xenomai/include/posix -L/usr/xenomai/lib -lstdc++ -lpthread_rt -lxenomai -lpthread -lrt -Wl,@/usr/xenomai/lib/posix.wrappers -pthread
then the mutex can never be acquired by any thread. Actually, I cannot lock it even if I place mtx.try_lock() on the first line of main().Also, if I try to sleep at sleep just before the end of attempt_10k_increases() with "std::this_thread::sleep_for", it does not sleep. Even if I increase the number of attempts, in order for the threads to stay alive for longer, I cannot see the threads show up in /proc/xenomai/stat .
What I observe is that when using -Wl,@/usr/xenomai/lib/posix.wrapper:- mutex::try_lock fails- std::this_thread::sleep_for() does not sleep- threads do not show up in /proc/xenomai/stat
So I have two questions:a) is there any way to get -Wl,@/usr/xenomai/lib/posix.wrappers to correctly wrap underlying calls to pthread_* functions which are hidden in libstdc++ ?b) is there any way to safely link into the same executable some code that calls pthread_* which you want to wrap in the Xenomai posix skin and C++ code which uses std::thread?
Thanks,Giulio


More information about the Xenomai mailing list