SFML community forums
Help => System => Topic started by: user31182 on July 04, 2013, 02:06:45 pm
-
I am working on a project with SFML, version 2, and I had been using std::thread for running some threads.
I am wondering why sf::thread does not require a join() function? And why is has a launch function whereas the standard library does not.
Also, since sfml is cross platform, what are the advantages and disadvantages between sf::thread and std::thread?
Apologies if this question has been answered before, the search isn't working at the moment. It displays an error message asking me to report the problem to an administrator. Hopefully and admin will see this, and then I will have done what the message told me to!
-
sf::Thread doesn't intend to compete with the standard library. SFML (written in C++03) uses threads internally and also offers them in the API. If you have C++11 available, you should use std::thread, because it's more feature-rich.
-
I am wondering why sf::thread does not require a join() function?
Because the destructor does it.
And why is has a launch function whereas the standard library does not.
Because the standard library can rely on move semantics, you can construct a std::thread really only when you need to launch it. SFML cannot rely on move semantics yet (because it must remain compatible with C++03 compilers), and thus it has to explicitly separate construction from launch.
Also, since sfml is cross platform, what are the advantages and disadvantages between sf::thread and std::thread?
Use std::thread if you can. There's absolutely no advantage to use sf::Thread.
Apologies if this question has been answered before
The last one is answered in the tutorial :P
the search isn't working at the moment
It never works. You must unselect irrelevant forums to make the request lighter, if you want to avoid this error.
-
Okay that's great thanks very much.
Seems a shame not to use sf::thread, because then everything would be "sf" - nice and uniform. But without .join() I would be a bit stuck, and since there isn't an advantage to use sf::thread, I won't bother with the hassle of learning the subtle differenced between then.
Cheers for the quick answer(s). :)
-
Seems a shame not to use sf::thread, because then everything would be "sf" - nice and uniform.
Huh? What's the point of reinventing the whole standard library wheel in SFML?
And no, you probably still use other libraries, at least the standard library. You will never have everything uniform...
-
But without .join()
sf::Thread::wait(). Sorry, I misunderstood you the first time you asked.