SDL Wiki
(This is the documentation for SDL3, which is under heavy development and the API is changing! SDL2 is the current stable version!)


Get the thread identifier for the specified thread.


SDL_threadID SDL_GetThreadID(SDL_Thread * thread);

Function Parameters

thread the thread to query

Return Value

Returns the ID of the specified thread, or the ID of the current thread if thread is NULL.


This thread identifier is as reported by the underlying operating system. If SDL is running on a platform that does not support threads the return value will always be zero.


This function is available since SDL 3.0.0.

Code Examples

#include "SDL.h"

// Very simple thread - counts 0 to 9 delaying 50ms between increments
int TestThread(void *ptr)
    int cnt;

    for (cnt = 0; cnt < 10; ++cnt) {
        SDL_Log("\nThread counter: %d", cnt);

    return cnt;

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

    SDL_Log("\nSimple SDL_CreateThread test:");

    /* Simply create a thread */
    thread = SDL_CreateThread(TestThread, "TestThread", (void *)NULL);

    if (NULL == thread) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "\nSDL_CreateThread failed: %s\n", SDL_GetError());

    /* Retrieve the ID for the newly launched thread */
    threadID = SDL_GetThreadID(thread);

    /* Wait for the thread to complete and get the return code */
    SDL_WaitThread(thread, &threadReturnValue);
    SDL_Log("\nThread returned value: %d", threadReturnValue);

    return 0;

CategoryAPI, CategoryThread

[ edit | delete | history | feedback | raw ]

[ front page | index | search | recent changes | git repo | offline html ]

All wiki content is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0).
Wiki powered by ghwikipp.