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. Application frozen by unix signal
Forum Updated to NodeBB v4.3 + New Features

Application frozen by unix signal

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 389 Views
  • 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.
  • tovaxT Offline
    tovaxT Offline
    tovax
    wrote on last edited by
    #1

    Hi, all
    I'm testing unix signal on Ubuntu, and the application will freeze after a few seconds. A very simple application and driver has been uploaded to github JCDemoDriver.
    I have read Calling Qt Functions From Unix Signal Handlers. In fact, there has been some discussion on this issue (here), and @JonB has been very helpful to me. Finally, I found that the freezing of applications has nothing to do with sockets. I think it may be that I do not have a sufficient understanding of the event system, so I would like to consult here about the causes of application freezing and how to solve this problem. The reason for re posting here is that I have received a lot of help in this forum section (General and Desktop) before. Please forgive me for doing so.
    Important details:
    (1) The driver sends signals with a high frequency, such as a 10 millisecond cycle.
    (2) There is a long period of sleep in the timerEvent of the application, and the sleep time is greater than the timer cycle.
    (3) Without a socket, simply setting up a unix signal handler can also cause the application to freeze.

    Best regards!

    1 Reply Last reply
    0
    • tovaxT Offline
      tovaxT Offline
      tovax
      wrote on last edited by
      #2

      In fact, the application does not completely crash. When the UI and timerEvent are frozen, the unixSignalHandler continuously outputs debugging information. I noticed a very strange detail: The debug message did not output the number 243. This exception occurs just when the application freezes.

      void PanelDriver::unixSignalHandler(int)
      {
          static int cnt = 0;
          qDebug() << __FUNCTION__ << cnt++;
      }
      

      debug output:

      ......
      timerEvent 170
      unixSignalHandler 240
      timerEvent 180
      unixSignalHandler 241
      timerEvent 190
      **unixSignalHandler 242**
      **unixSignalHandler 244**
      unixSignalHandler 245
      unixSignalHandler 246
      ......
      unixSignalHandler 11793
      unixSignalHandler 11794
      unixSignalHandler 11795
      unixSignalHandler 11796
      unixSignalHandler 11797
      unixSignalHandler 11798
      unixSignalHandler 11799
      unixSignalHandler 11800
      unixSignalHandler 11801
      unixSignalHandler 11802
      unixSignalHandler 11803
      unixSignalHandler 11804
      unixSignalHandler 11805
      unixSignalHandler 11806
      ......
      
      1 Reply Last reply
      0
      • tovaxT Offline
        tovaxT Offline
        tovax
        wrote on last edited by
        #3

        If a mutex is added to unixSignalHandler(), the application will permanently freeze at "unixSignalHandler xyz". xyz is an uncertain number in the range of 100 to 300.

        void PanelDriver::unixSignalHandler(int)
        {
            QMutexLocker locker(&mMutex);
            static int cnt = 0;
            qDebug() << __FUNCTION__ << cnt++;
        }
        

        debug output:

        ......
        timerEvent 120
        unixSignalHandler 136
        timerEvent 130
        unixSignalHandler 137
        timerEvent 140
        unixSignalHandler 138
        timerEvent 150
        unixSignalHandler 139
        timerEvent 160
        unixSignalHandler 140
        timerEvent 170
        unixSignalHandler 141
        timerEvent 180
        unixSignalHandler 142
        ***Freeze Forever***
        
        1 Reply Last reply
        0
        • tovaxT Offline
          tovaxT Offline
          tovax
          wrote on last edited by
          #4

          SOLVED:

          1. unixSignalHandler() must be a reentrant function.
          2. Cannot use qDebug() in the unixSignalHandler() function.
          3. This only applies if socketpair is not used. For more details about socketpair, please see this post.
          JonBJ 1 Reply Last reply
          1
          • tovaxT tovax

            SOLVED:

            1. unixSignalHandler() must be a reentrant function.
            2. Cannot use qDebug() in the unixSignalHandler() function.
            3. This only applies if socketpair is not used. For more details about socketpair, please see this post.
            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @tovax said in Application frozen by unix signal:

            unixSignalHandler() must be a reentrant function.

            That I would expect, in view of your usage being frequent.

            Cannot use qDebug() in the unixSignalHandler() function.

            This is sad, but not totally unexpected. I should have mentioned this possibility, but I just hoped it would be simple enough to work.

            tovaxT 1 Reply Last reply
            0
            • JonBJ JonB

              @tovax said in Application frozen by unix signal:

              unixSignalHandler() must be a reentrant function.

              That I would expect, in view of your usage being frequent.

              Cannot use qDebug() in the unixSignalHandler() function.

              This is sad, but not totally unexpected. I should have mentioned this possibility, but I just hoped it would be simple enough to work.

              tovaxT Offline
              tovaxT Offline
              tovax
              wrote on last edited by
              #6

              @JonB
              Thank you very much for your suggestion. You have guided me through many valuable tests, leading to the discovery of useful information.

              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