Problem with DCE and std::thread (probably a DCE bug?)

75 views
Skip to first unread message

Andreas Pantelopoulos

unread,
May 16, 2017, 8:50:33 AM5/16/17
to ns-3-users
Hello to all,

I posted yesterday a problem I had with porting a software switch executable in DCE, that uses std::thread. In this post I provide more details and a way to re-produce the problem easily. I managed to reproduce the problem with a very simple c++ program that uses two threads. The program exits with a SIGSEGV. Attached you will find the code for this simple program. I also attach the output of the gdb backtrace when the error occurs. I also modified the task-manager so as to print whenever it switches between threads. The cpp program is really simple: The main boots up a thread and this threads execute in a while loop, in which it sleeps for 2 seconds in each loop. The main thread also executes the same loop.

I attach the gdb result of "backtrace" command after the error occurs. What really bugs me is that the error is received in different points in each run. I believe this is a bug in DCE, or I understand and do something really really wrong, or both. 

My dce version is the 1.9 and the ns-3 version is the 3.26.

I compile the program with " g++ -std=c++11 -fPIC simple.cpp -pie -rdynamic -lpthread -o simple " and then I copy the executable in the /usr/local/bin (or wherever the DCE_PATH or DCE_ROOT points to). In order to execute it quickly you can modify the "myscripts/sleep" example to point to the "simple" binary. Also, comment the Simulator::stop() line in the script.

Any help with this issue would be greatly appreciated.

Thanks,
Andreas Pantelopoulos
simple.cpp
gdb_backtrace_output.txt

Andreas Pantelopoulos

unread,
May 16, 2017, 9:38:16 AM5/16/17
to ns-3-users
Continuing on the following post, I notice that if I comment any of the two std::this_thread::sleep_for() or both of them, the program executes just fine. Looking at the source code of sleep_for (https://gcc.gnu.org/onlinedocs/gcc-4.6.2/libstdc++/api/a01083_source.html) I observe that it calls nanosleep() which is captured by dce and wrapped around dce_nanosleep. Maybe there is a race condition in dce_nanosleep ?

Thanks,
Andreas

Andreas Pantelopoulos

unread,
May 16, 2017, 6:49:07 PM5/16/17
to ns-3-users
A little update for anyone that cares to help. 

So, std::thread indeed builds on good-old pthreads in my linux box, and all the calls from pthreads should be intercepted by the dce runtime system. However, by using manual breakpoints in gdb, I determined that when the call to pthread_create happens through std::thread, the DCE does not intercept it in order to create the thread in it's own thread management system. However, the rest system calls are, and thus a nasty race condition occurs. 

If anyone is willing to help solving that, preferably someone who has developed for DCE in the past, that would be awesome!

Andreas

Andreas Pantelopoulos

unread,
May 21, 2017, 12:36:59 PM5/21/17
to ns-3-users
In case anyone is wondering or experiences same issues with std::thread and ns3, the problem is solved by compiling and linking against libc++ from llvm. 

Also, compile against clang++.

Thanks for the help,
Andreas

Tommaso Pecorella

unread,
May 21, 2017, 7:34:12 PM5/21/17
to ns-3-users
Great to know Andreas.
I'm sorry if you had to figure out by yourself, but I can't build DCE on my computer, so I'm kinda useless on DCE-related issues.

T.
Reply all
Reply to author
Forward
0 new messages