SDK Thread API documentation

Version: beta

FUNCTION
dmThread::New() create a new thread
dmThread::Join() join thread
dmThread::AllocTls() allocate thread local storage key
dmThread::FreeTls() free thread local storage key
dmThread::SetTlsValue() set thread specific data
dmThread::GetTlsVAlue() get thread specific data
dmThread::GetCurrentThread() gets the current thread
dmThread::SetThreadName() sets the current thread name

Functions

dmThread::New()

dmThread::New(thread_start,stack_size,arg,name)

Create a new named thread

PARAMETERS

thread_start Thread entry function
stack_size Stack size
arg Thread argument
name Thread name

RETURNS

Thread handle

EXAMPLES

Create a thread
#include <dmsdh/sdk.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::HThread thread = dmThread::New(dmLogThread, 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);
}

dmThread::Join()

dmThread::Join(thread)

Join thread

PARAMETERS

thread Thread to join

dmThread::AllocTls()

dmThread::AllocTls()

Allocate thread local storage key

PARAMETERS

RETURNS

Key

dmThread::FreeTls()

dmThread::FreeTls(key)

Free thread local storage key

PARAMETERS

key Key

dmThread::SetTlsValue()

dmThread::SetTlsValue(key,value)

Set thread specific data

PARAMETERS

key Key
value Value

dmThread::GetTlsVAlue()

dmThread::GetTlsVAlue(key)

Get thread specific data

PARAMETERS

key Key

dmThread::GetCurrentThread()

dmThread::GetCurrentThread()

Gets the current thread

PARAMETERS

RETURNS

the current thread

dmThread::SetThreadName()

dmThread::SetThreadName(thread,name)

Sets the current thread name

PARAMETERS

thread the thread
name the thread name