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. How to Pause/stop all threads when one thread has SEG.FAULT

How to Pause/stop all threads when one thread has SEG.FAULT

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 2.8k 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.
  • S Offline
    S Offline
    sathishm
    wrote on last edited by
    #1

    Hi All,
    I have a Qt application which uses two threads(UI and Background). The application executes scripts for testing. the UI has a Tableview which is dynamically populated and background thread runs the scripts and provides necessary data to UI. Sometimes the UI thread panics in PaintEvent function. I suspect that the background thread is not giving proper data sometimes. To check the same i tried seeing the backtrace for the background thread but found that it was still running. since the segfault happens randomly and at different places everytime, it is difficult ot debug the issue. Can someone help me how to stop the background thread when UI thread is stopped?

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Hi,

      See http://stackoverflow.com/questions/7376228/linux-c-catching-kill-signal-for-graceful-termination for handling segfaults.

      [quote]the UI has a Tableview which is dynamically populated and background thread runs the scripts and provides necessary data to UI.[/quote]How do you update your table view? The table view is not thread-safe -- it can only be updated from the UI thread. Your background thread is not allowed to update it.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sathishm
        wrote on last edited by
        #3

        Hi,
        Whenever I need to update the table i will emit signal from bgthread and UI thread will update the same.

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          If you suspect is on background thread, we need to kill the culprit itself. I suggest you to start dumping the result of background thread in to a file and inspect. You said that data from bgthread is passed to ui thread using sig/slot. You should be able to print and see the data in slot as well. Not sure how big is the data too inspect.

          You can try the following as well if

          1. Get the current thread QThread::currentThread
          2. Connect finished() signal to slot - Not sure signal emits if thread crashes.
          3. Inside the slot, terminate other thread.

          This works only if the finished signal is emitted.

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          0
          • JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by
            #5

            [quote author="sathishm" date="1405665571"]Whenever I need to update the table i will emit signal from bgthread and UI thread will update the same.[/quote]Ok, that's the correct way to do it. (You did use AutoConnection or QueuedConnection, right?)

            I recommend using tools like Valgrind and Helgrind to help with debugging. They are designed specifically to detect memory errors and thread access errors.

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sathishm
              wrote on last edited by
              #6

              Hi, Thanks for the reply. First i will try Printing the data into a file(not sure if this will work as there are too many.)
              I will run Valgrind after this to check for any suspicious things happening.

              Also i have another doubt, There is one place in BgThread where i do the following :
              @
              tblview->scrollTo(startcolindex,QAbstractionItemView::PostionAtCenter);
              tblview->SelectionModel()->select(QItemSelection(startcolindex,endcolindex,QItemSelectionmodel::Rows));
              @

              Is this the wrong way, Should i use Signal and Slot mechanism to do this also?

              The reason why i suspect this is, it is the only place in BGthread where i change Qtable property.

              I am currently trying to run application commentiing the above lines. Will see if i still get any seg.faults.

              1 Reply Last reply
              0
              • dheerendraD Offline
                dheerendraD Offline
                dheerendra
                Qt Champions 2022
                wrote on last edited by
                #7

                I'm assuming that you are passing the tblview to thread and using it. I don't see issue in code. However it is suspect as well.

                I suggest you better use the signal/slot mechanism for update in the UI.

                Dheerendra
                @Community Service
                Certified Qt Specialist
                http://www.pthinks.com

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  sathishm
                  wrote on last edited by
                  #8

                  Thanks, I will implement Signal/slot to be on safer side anyway.

                  1 Reply Last reply
                  0
                  • JKSHJ Offline
                    JKSHJ Offline
                    JKSH
                    Moderators
                    wrote on last edited by
                    #9

                    [quote author="sathishm" date="1405680812"]Also i have another doubt, There is one place in BgThread where i do the following :
                    @
                    tblview->scrollTo(startcolindex,QAbstractionItemView::PostionAtCenter);
                    tblview->SelectionModel()->select(QItemSelection(startcolindex,endcolindex,QItemSelectionmodel::Rows));
                    @

                    Is this the wrong way, Should i use Signal and Slot mechanism to do this also?

                    The reason why i suspect this is, it is the only place in BGthread where i change Qtable property.[/quote]Your suspicion is correct. You must not call any functions of GUI classes in a background thread. This will cause crashes.

                    See this documentation: http://qt-project.org/doc/qt-5/threads-qobject.html It says "GUI classes, notably QWidget and all its subclasses, are not reentrant. They can only be used from the main thread."

                    Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                    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