Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Threads  (Read 1261 times)

0 Members and 1 Guest are viewing this topic.

c++er

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Threads
« 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 :)

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Threads
« Reply #1 on: July 08, 2013, 07:24:31 pm »
You could try C++11 concurrency API. For example, see std::future::wait_for
SFML / OS X developer

c++er

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Threads
« Reply #2 on: July 08, 2013, 07:33:32 pm »
Thanks Hiura for the fast answer.
But is this possible just with sf::Thread ?

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Threads
« Reply #3 on: July 09, 2013, 08:09:10 am »
sf::Thread is too basic for that job. You'd better use the std API.
SFML / OS X developer

 

anything