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

Author Topic: Why is there no thread.join() with SFML threads library?  (Read 3164 times)

0 Members and 1 Guest are viewing this topic.

user31182

  • Newbie
  • *
  • Posts: 23
    • View Profile
    • Email
Why is there no thread.join() with SFML threads library?
« 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!

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6276
  • Thor Developer
    • View Profile
    • Bromeon
Re: Why is there no thread.join() with SFML threads library?
« Reply #1 on: July 04, 2013, 02:19:04 pm »
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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Why is there no thread.join() with SFML threads library?
« Reply #2 on: July 04, 2013, 02:23:02 pm »
Quote
I am wondering why sf::thread does not require a join() function?
Because the destructor does it.

Quote
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.

Quote
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.

Quote
Apologies if this question has been answered before
The last one is answered in the tutorial :P

Quote
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.
Laurent Gomila - SFML developer

user31182

  • Newbie
  • *
  • Posts: 23
    • View Profile
    • Email
Re: Why is there no thread.join() with SFML threads library?
« Reply #3 on: July 04, 2013, 02:39:24 pm »
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). :)

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6276
  • Thor Developer
    • View Profile
    • Bromeon
Re: Why is there no thread.join() with SFML threads library?
« Reply #4 on: July 04, 2013, 02:48:16 pm »
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...
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Why is there no thread.join() with SFML threads library?
« Reply #5 on: July 04, 2013, 02:59:12 pm »
Quote
But without .join()
sf::Thread::wait(). Sorry, I misunderstood you the first time you asked.
Laurent Gomila - SFML developer

 

anything