SFML community forums

Help => General => Topic started by: c++er on July 08, 2013, 07:16:36 pm

Title: Threads
Post by: c++er on July 08, 2013, 07:16:36 pm
Hi ! Today I finished my C++ book, and i started with SFML. I tried to learn Threads,but I dont know how to use them right.  My question is : How can I make a program that wait 10 seconds for a int to be inputted,and print something if the int was entered or something else if the int was not entered...
I though so:
A thread that Sleep(10000)'s,using Windows.h and a thread that cin's a number.The number is passed to the thread by reference.At the end of the sleep-thread I want to stop the input thread,but than I discovered that the thread cannot be stopped :( . How can I do this , using SFML threads ?
Thanks in advance :)
Title: Re: Threads
Post by: Hiura on July 08, 2013, 07:24:31 pm
You could try C++11 concurrency API. For example, see std::future::wait_for (http://en.cppreference.com/w/cpp/thread/future/wait_for)
Title: Re: Threads
Post by: c++er on July 08, 2013, 07:33:32 pm
Thanks Hiura for the fast answer.
But is this possible just with sf::Thread ?
Title: Re: Threads
Post by: Hiura on July 09, 2013, 08:09:10 am
sf::Thread is too basic for that job. You'd better use the std API.