Results 1 to 6 of 6

Thread: workerThread calling static QVector - will freeze if not running for many hours

  1. #1
    Join Date
    Aug 2017
    Posts
    7
    Qt products
    Qt5
    Platforms
    Windows

    Default workerThread calling static QVector - will freeze if not running for many hours

    I have a application that parses a UDP stream. Then monitor that stream for a trigger event to start my thread. within that thread is a worker thread that calls a function which contains a static QVector. On every trigger event I initiate a vector.swap and vector.resize/reserve (have used both with same results).

    with the program running and continually receiving UDP data. It runs beautifully with not issues. This data is then written to MySQL. a second thread is also running and writing reference data to another table in MySQL. Both MySQL write functions are on separate connections.

    However if my program is left running overnight with no UPD stream. My program will hang and must be re-started to work again. This is not the case with 4 hours of no UDP. I have not determined a specific time as of yet. Not sure if my issue id with my Thread or my Vector. The 2nd thread function will pick up and continue to run normally.

    Below are a few code snippets.

    System Windows 7 Prof.
    creator 4.1.0
    Qt 5.6.2(Gcc 6.1.0, 64 bit)
    using C++11

    Qt Code:
    1. [Main Thread]
    2. {
    3. frmThread = new QThread;
    4. workerThread = new StreamToVector();
    5. workerThread->moveToThread(frmThread);
    6. connect(workerThread, &DataStreamToVector::destroyed, frmThread, &QThread::quit);
    7. connect(workerThread, &DataStreamToVector::destroyed, workerThread, &DataStreamToVector::deleteLater);
    8. connect(this, &DataStreamToBuffer::DataToVector_Signal, workerThread, &DataStreamToVector::parseStreamToVector_Slot, Qt::DirectConnection);
    9. frmThread->start();
    10.  
    11. DataToVector_Signal(dataStream, dataSize, RecordsPerTriggerEvent);
    12. }
    13.  
    14. [worker thread .h ]
    15. QThread *frmThread;
    16.  
    17. [worker thread .cpp ]
    18. void DataStreamToVector::parseStreamToVector_Slot(QString dataStream, int dataSize, uint RecordsPerTriggerEvent)
    19. {
    20. static QVector < QVector<QString> > cycleBuffer(63, QVector<QString>(MAX_CYCLE_SIZE_x10MS));
    21. static uint recordCnt = 1;
    22.  
    23. if ( recordCnt > RecordsPerTriggerEvent ) {
    24. QVector < QVector<QString> > defaultBuffer(63, QVector<QString>(MAX_CYCLE_SIZE_x10MS));
    25. recordCnt = 1;
    26. cycleBuffer.swap(defaultBuffer);
    27. cycleBuffer.reserve(GALIL_40x0_ADDRESS_COUNT);
    28. }
    29.  
    30. if ( recordCnt <= recPerCycle ) {
    31. cycleBuffer[0][recordCnt].append(dataStream.mid( 12,2 )); // general Input Block 0 address
    32. cycleBuffer[1][recordCnt].append(dataStream.mid( 14,2 ));
    33. // recordCnt typically 350 - 800
    34.  
    35. if ( recordCnt == RecordsPerTriggerEvent )
    36. writeRecordsToDB(RecordsPerTriggerEvent, cycleBuffer);
    37.  
    38. recordCnt++;
    39. }
    To copy to clipboard, switch view to plain text mode 

    any insight or direction would be appreciated. Thank You,
    Last edited by swankster; 28th August 2017 at 15:45.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: workerThread calling static QVector - will freeze if not running for many hours

    Qt Code:
    1. connect(this, &DataStreamToBuffer::DataToVector_Signal, workerThread, &DataStreamToVector::parseStreamToVector_Slot, Qt::DirectConnection);
    To copy to clipboard, switch view to plain text mode 
    Why is this a direct connection? This is definitely incorrect as it makes your parseStreamToVector function execute in the main thread instead of the worker thread which is probably not what you want.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Aug 2017
    Posts
    7
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: workerThread calling static QVector - will freeze if not running for many hours

    I originally had Qt::QueuedConnection and tried direct but forgot to put it back. either way returned the same result.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: workerThread calling static QVector - will freeze if not running for many hours

    Please run your application under a debugger. When the freeze occurs, break the application, dump the backtrace and show it to us.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Aug 2017
    Posts
    7
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: workerThread calling static QVector - will freeze if not running for many hours

    I ran in debug before an it did not fail. Ran it again last night and it did. It appears thread and vector are working fine. It thinks my MySQL table has been truncated.
    Thanks for having me check the obvious.

  6. #6
    Join Date
    Aug 2017
    Posts
    7
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: workerThread calling static QVector - will freeze if not running for many hours

    this post is [SOLVED] the issue has nothing to do with QThread or QVector. It is MySQL connection getting hung-up.

Similar Threads

  1. Replies: 1
    Last Post: 21st February 2014, 17:33
  2. X process 99% after 2 hours using drawPixmap
    By gab74 in forum Qt Programming
    Replies: 6
    Last Post: 24th January 2013, 18:02
  3. How do i get the number of hours
    By ayanda83 in forum Newbie
    Replies: 2
    Last Post: 4th January 2013, 10:21
  4. Replies: 5
    Last Post: 2nd September 2011, 23:11
  5. Date and hours
    By kjiu in forum Qt Programming
    Replies: 9
    Last Post: 13th November 2009, 18:27

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.