views:

128

answers:

1

I seem to be getting an exception generated only with a thread created with Qtconcurrent::run

I have a class named FPSengine which has a method named FPSengine::getData() that is called by the main thread and 3 other threads (2 QThreads and 1 made with QtConcurrent::run()). Inside FPSengine::getData() I call QTime::currentTime(). If I call FPSengine::getData() from the main thread or one of the QThreads I dont have any problems but when I call FPSengine::getData() from the thread created with Qtconcurrent::run() I sometimes get an exception. Could there be something wrong with Qtconcurrent or QTime:currentTime() or even tzset (which is called by QTime::currentTime from what the gdb stack shows)? Or is there something wrong with my code. Here is the stack info of the failing thread:
0 raise /lib/libc.so.6 0
1 abort /lib/libc.so.6 0
2 ?? /lib/libc.so.6 0
3 ?? /lib/libc.so.6 0
4 free /lib/libc.so.6 0
5 ?? /lib/libc.so.6 0
6 tzset /lib/libc.so.6 0
7 QTime::currentTime() /usr/lib/libQtCore.so.4 0
8 FPSengine::xmitData FPSengine2.cpp 93
9 FPSengine::getData FPSengine2.cpp 21
10 threadDatalog::run threaddatalog.cpp 109
11 ?? /usr/lib/libQtCore.so.4 0
12 start_thread /lib/libpthread.so.0 0
13 clone /lib/libc.so.6 0 14 ?? 0

+1  A: 

QTime::currentTime() (or any of the QTime functions, really) are not documented as being concurrent. Also, I doubt that the underlying call (tzset) is designed to handle concurrency very well. Accordingly, you'll probably need to add some protection, such as a mutex, around the call to get the current time to prevent simultaneous access. I don't know if this will solve your issue, but it will probably help.

Caleb Huitt - cjhuitt
thx, I was able to change my code to not use these calls anymore and the problem did go away
yan bellavance