[Interest] Expected event execution order in this multi-thread application

Richard Weickelt richard at weickelt.de
Sun Sep 29 11:49:36 CEST 2019


what is the expected event execution order in the following scenario?

- 2 Threads running their event loop
- Thread T1 is handling an event E1
- Thread T2 sends an event E2 to T1 (queued)
- Thread T1 (still handling E1) emits an event E3 to itself (direct) after
E2 has already been enqueued.
- E3 is a very long-running event. To prevent events from starving, T1 calls
QCoreApplication::processEvents() periodically.

Observed behaviour:
- E3 gets immediately executed
- E2 is executed after E3/E1 have completed

Is this behavior expected? I would expected E2 being executed at least on
the first invocation of QCoreApplication::processEvents(), but apparently it
sits in the event queue until T1 returns from E3 (and also E1).

In my scenario E2 is rather short and E3 expectes something from E2 in order
to complete. So I run into a deadlock here.

Would it be a solution to handle E3 in a queued connection? In case E2 is
posted after E3 has started, would E2 be executed by processEvents()?


More information about the Interest mailing list