bitwiseworks / qtbase-os2

Port of Qt Base module version 5 to OS/2
Other
10 stars 2 forks source link

Compress notifications from QProcess watcher #62

Open dmik opened 5 years ago

dmik commented 5 years ago

The OS/2 implementation of QProcess uses the watcher thread to monitor process I/O and termination. Notifications about monitored events are sent using the Qt event system (QMetaObject::invokeMethod). In theory, there may be so many notifications that they would flood internal Qt buffers and lead to unexpected results.

One scenario for such notification floods is child termination. There is no API in OS/2 to monitor the termination of a set of children — the parent may wait for only one or all. We have to wait for all in order to be able to detect termination of multiple child processes. And when we get such a notification, we have to check all running processes for termination and this results in asynchronous Qt method invocations via its event queue. I.e. if we have 10 processes, then each of terminations will cause 10 invocations. So if they all end at the same time, there will be around 100 events pending on the thread that started those processes. This is quite a lot given there may be other notifications (from each process I/O pipes) as well as other Qt events besides that.

An obvious solution is to compress notifications to make sure that each QProcess object doesn't have more than one termination or pipe state event at the same time. This would reduce the amount of notifications to just 10 in the above example.

dmik commented 5 years ago

This was found while working on #60 and in particular on tst_QSystemSemaphore::processes.