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

Author Topic: sf::thread  (Read 13439 times)

0 Members and 1 Guest are viewing this topic.

Regen

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Email
sf::thread
« on: August 01, 2008, 11:59:16 am »
I think it would be nice to add a function to the sf::thread class.
A IsRunning() thingy.
I know the tutorial suggests to have a globel bool called ThreadRunning, but if you have alot of threads i could be messy, i dont like to use globals at all :?
Why can't things just work?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sf::thread
« Reply #1 on: August 01, 2008, 02:35:53 pm »
Well, you're using a derived class for your own threads right ? (yes you do, using callbacks is not clean C++ and is meant only for compatibility with other languages).
So you can just add this feature to your class.

Code: [Select]
class MyThread : public sf::Thread
{
public :

    MyThread() : IsRunning(false) {}

    bool IsRunning() const {return IsRunning;}

private :

    virtual void Run()
    {
        IsRunning = true;

        // ...

        IsRunning = false;
    }

    bool IsRunning;
};
Laurent Gomila - SFML developer