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



  • Any chance of upgrading to 4.7.3 to check if the issue remains in that version? It is just a patch upgrade from 4.7.0...



  • Hi Andre,

    Thanks for your reply.

    I will check in 4.7.3 as you said. Do you see any issue in the code? (Or) aware of issues in Qt 4.7.0 with tls?

    -Kartlee



  • I get the same crash even in 4.7.3.

    -Karthik



  • This is a warning in the source of [[Doc:QThreadStorage]]:

    bq. QThreadStorage can only be used with threads started with QThread

    So, I suspect this to be the cause of your problems.
    Also, a Q(Core)Application is not running, which may cause problems too.



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.