SFML community forums
Help => System => Topic started by: b3ngr33ni3r on December 12, 2011, 12:40:22 am
-
Hey guys, quick question. i'm trying to get user input while still running another thread (this other thread is drawing a sf::RenderWindow). however, when attempting to cin in the thread, it pauses the entire program, causing the sf::RenderWindow to freeze up. So, i'm wondering how to get userinput in a thread while not stopping the main program (i'm guessing i can't use cin)
Thanks.
-
You're probably doing something wrong, using std::cin in a thread shouldn't block other threads.
-
Okay, would you mind taking a look?
The pertinent info is Init() which calls Listener() where Listener() tries to std::cin.
https://github.com/b3ngr33ni3r/Magnet/blob/experimental/Console/Console.cpp
https://github.com/b3ngr33ni3r/Magnet/blob/experimental/Console/Console.h
-
That is odd, it seems as though cin is pausing the thread, but it shouldn't
-
Your sf::Thread instance is destroyed as soon as the thread is launched (because it is local), and the destructor of sf::Thread calls Wait(). So it's exactly as if you called the Console::Listener function directly. The sf::Thread instance must be alive as long as the thread runs ;)
-
Ah, Perfect. All set now. Thanks!