Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Best Way to Poll for a Flag in Main Event Thread
Forum Updated to NodeBB v4.3 + New Features

Best Way to Poll for a Flag in Main Event Thread

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 486 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    leinad
    wrote on last edited by
    #1

    Hi,

    I know several folks have asked similar questions on this topic but there doesn't seem to be an answer which will work for my situation, at least none that I can find.

    I have multiple threads running, say 10. As each thread runs and when it completes a certain task it emits a signal to the main event thread.
    The slot in the main event thread keeps track of each thread that completes it task. The threads do not die, they just keep working after they send the signal.

    Once all the threads send their signal, the slot sets a flag completed.

    In the main event thread I go through a sequence of processing but can't continue until the flag in the slot shows complete. I don't want to holdup the
    main event thread because it still needs to receive slot information plus other information from other threads unrelated to the ones I'm mentioning.
    Does anyone know how I can poll for the flag without continuing to next phase in the process until the flag is set without holding up the main thread?

    I read about using single shot but not sure how to use that without continuing. I don't want to use a while loop to spin with aQthread ::sleep because
    that will hold up the thread sounds like poor practice. Any help will be appreciated.

    Thanks in advance!

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @leinad said in Best Way to Poll for a Flag in Main Event Thread:

      Does anyone know how I can poll for the flag without continuing to next phase in the process until the flag is set without holding up the main thread?

      emit a signal and call the next step in the connected slot.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • L Offline
        L Offline
        leinad
        wrote on last edited by
        #3

        Sounds so simple, and if I just return from the slot in case the flag is not set, the pointer will just sit in the main event loop servicing the other slots?

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved