0

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.

RghtHndSd
  • 117
  • 5

1 Answers1

-3

One way to accomplish it (also in a cross-platform manner) is to use libSDL's, SDL_KeyboardEvent.

Peter K
  • 1,787
  • 13
  • 15
  • Can you flesh this out a little more? How does one use this to wake up a thread? – RghtHndSd May 03 '16 at 14:49
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/12229849) – Igor Ivancha May 03 '16 at 18:49
  • @IgorIvancha: Sorry if I'm being dense, but I fail to see how the link answers the question. How does one use this to wake up a sleeping thread? – RghtHndSd May 04 '16 at 02:33