Application frozen by unix signal
-
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!
-
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 ......
-
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***
-
@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.