From: Lorenzo N. <Lor...@ii...> - 2015-02-19 10:32:24
|
Dear Tim, can share the code that triggers this problem? Is it simple enough for us to look? We could check to see if you are using YARP in some way which can cause troubles. Lorenzo From: Truong Nghiem [mailto:nxt...@ya...] Sent: mercoledì 18 febbraio 2015 09:40 To: rob...@li... Subject: [rc-hackers] Yarp threads and C++11 mutex Hello, I am using the current version of Yarp on Mac OS, installed with homebrew. I am developing a program in which there are multiple Yarp ports receiving inputs (for which I use callback method onRead() and set useCallback()). The onRead() callback method processes the received inputs and pushes them to a shared queue, managed and to be processed by another thread (let's call it the "main thread"). As I understand, the onRead() method is called in Yarp threads associated with the ports. The main thread and the shared queue use the C++11 standard (std::) thread, mutex, and condition variable. I have tested the main thread and the shared queue very carefully without Yarp, and they work fine. However, when I run my program with Yarp, the first call to std::mutex lock from a Yarp thread always cause a segmentation fault. I spent two hours inspecting the problem carefully and couldn't find any problem in my program, except the fact that I mix Yarp threads and standard mutex/thread. So I suspect the culprit is that Yarp doesn't work with C++11 mutex/thread. My questions are: 1) Is my conclusion correct? Can't I mix Yarp threads and C++11 mutex/thread? 2) How should I solve this issue? I don't want to rewrite my code to use Yarp thread and mutex because I have invested heavily in my current code, and there are many other parts / libraries of my program which already use the standard thread / mutex. I figure that maybe I will need to create std::thread's in which I manually poll the Yarp ports and bypass the callback mechanism of Yarp. However, this is inefficient in terms of resource usage because, I think, Yarp already creates many threads for its ports. I also see an experimental option in Yarp called YARP_EXPERIMENTAL_CXX11, which is OFF by default. Might turning on that option help to solve my problem? Thank you in advance! Tim |