SFML community forums

General => Feature requests => Topic started by: Regen on August 01, 2008, 11:59:16 am

Title: sf::thread
Post by: Regen 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 :?
Title: sf::thread
Post by: Laurent 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;
};