目次 - API(機能別) - スレッド - SDL_GetThreadID

SDL_GetThreadID

指定のスレッドのスレッドIDを得る

構文

SDL_threadID SDL_GetThreadID(SDL_Thread* thread)

引数

thread調査するスレッド

戻り値

指定のスレッドのスレッドIDを戻す. threadがNULLの場合は現在のスレッドのスレッドIDを戻す.

サンプルコード

#include <stdio.h>
#include "SDL_thread.h"

// とても単純なスレッド - 50ms間隔で0から9までカウントする
int TestThread(void *ptr)
{
    int cnt;

    for (cnt = 0; cnt < 10; ++cnt) {
        printf("\nスレッドカウンタ: %d", cnt);
        SDL_Delay(50);
    }

    return cnt;
}

int main(int argc, char *argv[])
{
    SDL_Thread *thread;
    int         threadReturnValue;

    printf("\nSDL_CreateThreadの単純なテスト:");

    /* 単にスレッドを生成する */
    thread = SDL_CreateThread(TestThread, "TestThread", (void *)NULL);

    if (NULL == thread) {
        printf("\nSDL_CreateThread 失敗: %s\n", SDL_GetError());
        exit(-1);
    }

    /* 新たに生成されたスレッドのIDを受け取る */
    threadID = SDL_GetThreadID(thread);

    /* スレッドが完了するのを待ち戻り値を得る */
    SDL_WaitThread(thread, &threadReturnValue);
    printf("\nスレッドの戻り値: %d", threadReturnValue);

    return 0;
}

詳細

このスレッドIDはOSによって報告される. スレッドに対応していない環境の場合は, 戻り値は常に0である.

関連項目(関数)

SDL_ThreadID

SDL Wikiへのリンク

SDL_GetThreadID - SDL Wiki