mardi 3 mai 2016

Multithreaded console application: Pause on keypress without busy waiting

I am writing a multithreaded console application in C++11. I would love for it to be OS independent, but I am on a linux machine.

I want to be able to pause threads upon a keypress, but for the program to be allowed to finish and exit without any keypresses as well. Currently my pseudocode for my main thread is the following.

while other threads are executing
  sleep for 1 second
  if keypress
    *do stuff*
  end if
end while

So it's something like a busywait. I was wondering if there is a better way to do this.

Aucun commentaire:

Enregistrer un commentaire