QThreadStorage crash in Windows - 4.7.0
-
Hi,
I am using QThreadStorage for to store thread specific data and boost threads to spawn desired number of threads. I get a strange crash in Windows [ Version 6.0.6002 ] in QThreadStorage's hasLocalData(). Below is the stack trace of the crash -
@QtCore4.dll!6701c468()
[Frames below may be incorrect and/or missing, no symbols loaded for QtCore4.dll]
QtCore4.dll!6701efa5()
QtCore4.dll!6701f010()
QtCore4.dll!6701ea6a()testc.exe!QThreadStorage<TEST >::hasLocalData() Line 140 + 0x10 bytes C++
testc.exe!test_log_stream() Line 35 + 0xc bytes C++
testc.exe!test_thread_run() Line 51 C++
testc.exe!boost::detail::thread_data<void (__cdecl)(void)>::run() Line 57 C++
testc.exe!boost::`anonymous namespace'::thread_start_function() + 0x5b bytes C++
msvcr90.dll!_callthreadstartex() Line 348 + 0x6 bytes C
msvcr90.dll!_threadstartex(void * ptd=0x00d41fe0) Line 326 + 0x5 bytes C
kernel32.dll!7755eccb()
ntdll.dll!77b0d80d()
ntdll.dll!77b0da1f()@We are using Qt 4.7.0 built with VS 2008. Here is the below code to reproduce the crash -
@#include <QtCore/qcoreevent.h>
#include <boost/thread.hpp>#include <iostream>
#include <sstream>
#include <list>
using namespace std;#include <stdlib.h>
class TEST
{
public:int range_error;
TEST() { range_error = 0; } ~TEST() { }
};
Q_GLOBAL_STATIC(QThreadStorage<TEST*>, tlsTEST)
/***************************************************************************/
void test_log_stream()
{
TEST inst;
if(!tlsTEST()->hasLocalData())
{
inst = new TEST();
tlsTEST()->setLocalData(inst);
}
inst = tlsTEST()->localData();
inst->range_error = 1;
}/**************************************************************************/
void test_thread_run( void )
{test_log_stream();
return;
}int main( int argc, char ** argv )
{int num_of_threads = 40;
list<boost::thread *> threadList;
for(int i = 0; i < num_of_threads; ++ i)
threadList.push_back(new boost::thread(test_thread_run));list<boost::thread >::iterator it;
for(it = threadList.begin(); it != threadList.end(); ++ it)
{
boost::thread t = *it;
t->join();
}return 0;
}@
If I am doing anything wrong in the usage of tls, please let me know.
-Kartlee
-
-
Hi,
Thanks for your reply.
What you mentioned was clearly mentioned as a caveat in 4.2 -
http://doc.qt.nokia.com/4.2/qthreadstorage.html
But this is no longer mentioned in 4.7 -
http://doc.qt.nokia.com/4.7/qthreadstorage.html
Should we not take it for granted that it works with non Qt threads?
-Karthik
-
[quote author="kartlee" date="1314379149"]
Should we not take it for granted that it works with non Qt threads?
[/quote]As the warning is still in the source code, I would say no, it only works with QThread, but not with with threads started using platform-specific APIs or other libraries like boost.