Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-87626

EventLoop cannot quit if "quit" is requested before "exec"

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P3: Somewhat important
    • None
    • 5.14.2
    • Core: Event loop
    • None
    • All

    Description

      Please kindly reference the attached "test-case.txt".

      `EventLoop` is a public class which is very convenient to build a message queue (Thanks a lot for the great work!). One of the classic use case is:

      1. A worker thread is running `EventLoop::exec()` to process events.
      2. Other threads call `QMetaObject::invokeMethod` to queue jobs (very lightweight jobs can be processed as events).
      3. A Control thread (usually the main thread) calls "EventLoop::quit" when quitting the Application.

      However, if the control thread is moving too fast to call "quit" before the worker thread to call "exec", the "exit" flag will be cleared by "exec", so "exec" will never quit.

      Please see the implementation of 

      ```
      QEventLoop::exec
      ```
      There is a line
      ```d->exit.storeRelease(false);```
      inside `LoopReference`.
      I am not familiar with how the different level of event loops are implemented, and it seems we may set "exit" flag as "false" when constructing an "EventLoop" rather than inside "exec", so if the "exit" flag is set as "true" before entering "exec" it will still work. 
       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            pengyunquan Peng Yunquan
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes