namespace Urho3D
{

/// Operating system thread.
class URHO3D_API Thread
{
public:
    /// Construct. Does not start the thread yet.
    Thread();
    /// Destruct. If running, stop and wait for thread to finish.
    virtual ~Thread();
    
    /// The function to run in the thread.
    virtual void ThreadFunction() = 0;
    
    /// Start running the thread. Return true if successful, or false if already running or if can not create the thread.
    bool Run();
    /// Set the running flag to false and wait for the thread to finish.
    void Stop();
    /// Set thread priority. The thread must have been started first.
    void SetPriority(int priority);
    
    /// Return whether thread exists.
    bool IsStarted() const { return handle_ != 0; }
    
protected:
    /// Thread handle.
    void* handle_;
    /// Running flag.
    volatile bool shouldRun_;
};

}
