Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QThreadStorage crash in Windows - 4.7.0
Forum Updated to NodeBB v4.3 + New Features

QThreadStorage crash in Windows - 4.7.0

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 3.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kartlee
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kartlee
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kartlee
          wrote on last edited by
          #4

          I get the same crash even in 4.7.3.

          -Karthik

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            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.

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • K Offline
              K Offline
              kartlee
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #7

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

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved