GetState
This function gets the current state of a thread.
Syntax
Returns
Returns the thread state. This may be one of the following values:
Thread::Running: the thread is still running.
Thread::Finished: the thread is finished running.
Example
#include "Leadwerks.h"
using namespace Leadwerks;
Mutex* mutex = NULL;
Object* ThreadFunction(Object* object)
{
for (int i = 0; i < 1000; i++)
{
//Lock the mutex so the two threads don't interfere with each other
mutex->Lock();
System::Print("Thread 2 printing...");
//Unlock the mutex so the other thread can run
mutex->Unlock();
Leadwerks::Time::Delay(1);
}
//Create something to give back to the main thread
Vec3* v = new Vec3(1, 2, 3);
return v;
}
int main(int argc, const char *argv[])
{
//Create a mutex
mutex = Mutex::Create();
//Create a thread. This will launch into the thread function
Thread* thread = Thread::Create(ThreadFunction);
//Wait for the thread to finish
while (thread->GetState() != Thread::Finished)
{
//Lock the mutex so the two threads don't interfere with each other
mutex->Lock();
System::Print("Thread 1 printing...");
//Unlock the mutex so the other thread can run
mutex->Unlock();
Leadwerks::Time::Delay(1);
}
//Get the thread result
Object* result = thread->GetResult();
System::Print(result);
//Cleanup
result->Release();
thread->Release();
mutex->Release();
return 0;
}