Create a new named thread
thread_start - Thread entry function
stack_size - Stack size
arg - Thread argument
name - Thread name
Thread - handle
Create a thread
#include <stdio.h>
#include <dmsdk/dlib/thread.h>
struct Context
{
bool m_DoWork;
int m_Work;
};
static void Worker(void* _ctx)
{
Context* ctx = (Context*)_ctx;
while (ctx->m_DoWork)
{
ctx->m_Work++; // do work
dmTime::Sleep(10*1000); // yield
}
}
int StartThread()
{
Context ctx;
ctx.m_DoWork = true;
ctx.m_Work = 0;
dmThread::Thread thread = dmThread::New(Worker, 0x80000, (void*)&ctx, "my_thread");
// do other work...
// ..eventually stop the thread:
ctx.m_DoWork = false;
// wait for thread
dmThread::Join(thread);
printf("work done: %d\n", ctx.m_Work);
}
Join thread. Waits for the thread specified by thread to terminate. If that thread has already terminated, then Join() returns immediately. The thread specified by thread must be joinable (see Detach()).
thread - Thread to join
Detach thread. When a detached thread terminates, its resources are automatically released back to the system without the need for another thread to join with the terminated thread.
thread - Thread to detach
Allocate thread local storage key
Key -
Free thread local storage key
key - Key
Set thread specific data
key - Key
value - Value
Get thread specific data
key - Key
Gets the current thread
the - current thread
Sets the current thread name
thread - the thread
name - the thread name