PDA

View Full Version : Confusing bug with threaded application



kachofool
15th December 2009, 22:23
Hey all,

I'm using QThreads in my application. At some points during my program, I enable and disable signals by calling (blockSignals(bool)) on objects that signal the threads. In one particular case, I unblock an object communicating with one of my threads in this manner. After about a second, the application crashes. I verify that the signals *do* unblock, and the event processing loop of the thread continues for a few iterations before crashing. The specific error I receive is:

terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::substr

But this isn't referring my code (at least I don't think it is). After running a backtrace with gdb, I get something like:


(gdb) backtrace
#0 0xb7fe2422 in __kernel_vsyscall ()
#1 0xb71954d1 in raise () from /lib/tls/i686/cmov/libc.so.6
#2 0xb7198932 in abort () from /lib/tls/i686/cmov/libc.so.6
#3 0xb73b04df in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/libstdc++.so.6
#4 0xb73ae415 in ?? () from /usr/lib/libstdc++.so.6
#5 0xb73ae452 in std::terminate() () from /usr/lib/libstdc++.so.6
#6 0xb73ae50b in __cxa_rethrow () from /usr/lib/libstdc++.so.6
#7 0xb753e6e2 in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib/libQtCore.so.4
#8 0xb75692ca in ?? () from /usr/lib/libQtCore.so.4
#9 0xb6fb3e78 in g_main_context_dispatch () from /lib/libglib-2.0.so.0
#10 0xb6fb7720 in ?? () from /lib/libglib-2.0.so.0
#11 0xb6fb7853 in g_main_context_iteration () from /lib/libglib-2.0.so.0
#12 0xb756902c in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/libQtCore.so.4
#13 0xb753cc79 in QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/libQtCore.so.4
#14 0xb753d0ca in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/libQtCore.so.4
#15 0xb744ab73 in QThread::exec() () from /usr/lib/libQtCore.so.4
#16 0x0805acb9 in DeviceThread::run (this=0x81a4648) at AxisCouple.cpp:487
#17 0xb744de32 in ?? () from /usr/lib/libQtCore.so.4
#18 0xb73eb80e in start_thread () from /lib/tls/i686/cmov/libpthread.so.0
#19 0xb72377ee in clone () from /lib/tls/i686/cmov/libc.so.6


The only relevant line in my code is:


(gdb) frame 16
#16 0x0805acb9 in DeviceThread::run (this=0x81a4648) at AxisCouple.cpp:487
487 exec();


I'm confused because I'm not calling exec(), or run() on the thread when it crashes. The thread is running when the program starts, and runs for quite awhile without issues. Only when I block objects talking to this thread, and then unblock them does this issue occur. I'm trying to figure out what the problem is... generally in multithreaded apps the problems are due to race conditions / thread safety etc. But I have no idea how to interpret the gdb output. I'd really appreciate any insight.

wysota
15th December 2009, 23:32
Please show us your code. Especially the part where you block signals.