View Full Version : Application leads to hang on continuously reading from QProcess stdout

18th March 2011, 07:08

I have an application built using QT-3.3.8. This is using a QProcess to
run an utility. The utility takes input and gives output. The input and output
data size is average, but there are too many read and writes to the QProcess.
After execution for a long time(30 minutes or so) the application hangs.
While debugging I found that the application is stuck in "read" system call.
This is part of socketRead function of QT, which is called on calling
readStdout of QProcess. I am reading from the stdout of QProcess for every 10 micro
seconds using a thread.

As per the documentation readStdout() is a non-blocking function. But I
don't know what causes this to block.

Can somebody give any clue to come out of this hang situation ?

Thanks in advance,

18th March 2011, 07:41
Are you really polling the standard output of the sub-process 100,000 times per second on the chance that there is some output? Seems you should just be waiting for readyReadStdout() to be emitted and then read (a separate thread may not be needed).

This could be a deadlock caused by unsynchronised access from multiple threads. It could be a memory leak finally crippling the program after 30 minutes.

18th March 2011, 08:43
Thank you for the quick reply Chris.

Yes, there is chance of having data to read after every 10 micro seconds.
I could use the readyReadStdout() signal, but that may not give performance like
the thread.

I will give a try.


19th March 2011, 06:02
Use of readyReadStdout did not help as the thread waiting for output was timing out.
There seems to be a deadlock because of two Mutexes in the present implementation.

Can you please suggest a tool which I can use to detect deadlock ?

I tried with Helgrind (part of valgrind 2.2.0). But the valgrind itself crashed due to bug in it.
Also I cannot use latest valgrind as this does not support Helgrind.

Thanks in advance,