Wait
This function will pause the current thread until the specified thread is finished running.
Syntax
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
thread->Wait();
//Get the thread result
Object* result = thread->GetResult();
System::Print(result);
//Cleanup
result->Release();
thread->Release();
mutex->Release();
return 0;
}