I'm trying to debug a thread issue. In most cases, it's easy, but with this one something gets stuck and I'm having difficulties finding the threads that causes the issue. (It happens after several hours and writing logs breaks the timings so... it's difficult as I can't just change the code to help me find the culprit).
Today, I was thinking to:
Hit Ctrl-C
I tried to determine which thread it is:
thread 9 where
That looked like a good bet. A thread waiting for data on a FIFO...
I decided to verify my theory by entering:
finish
The program started again, but gdb never stopped...
Am I correct thinking that proves that this FIFO never receives any data and that's where my process is stuck? (i.e. when data is received that function returns)
CodePudding user response:
Am I correct thinking that proves that this FIFO never receives any data
Yes: if your description is accurate, then it is likely that thread 9 is stuck waiting for data.
and that's where my process is stuck?
That we can't tell. A thread waiting on a FIFO could be expecting data from an external source (it is somewhat unusual and inefficient to have a FIFO that transfers data within a single processs), and if the other end of the FIFO is connected to some other process, then the fact that a thread was stuck there proves nothing.
P.S. One of the common ways that mixing FIFOs and threads causes hangs is also using fork
or other functions which create subprocesses -- it is exceedingly difficult to make such code correct in multithreaded environment.