Get the thread identifier for the specified thread.
Defined in <SDL3/SDL_thread.h>
SDL_ThreadID SDL_GetThreadID(SDL_Thread *thread);
SDL_Thread * | thread | the thread to query. |
(SDL_ThreadID) 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.1.3.
#include <SDL3/SDL.h>
#include <stdlib.h>
// Very simple thread - counts 0 to 9 delaying 50ms between increments
int TestThread(void *ptr)
{int cnt;
for (cnt = 0; cnt < 10; ++cnt) {
"Thread counter: %d", cnt);
SDL_Log(50);
SDL_Delay(
}
return cnt;
}
int main(int argc, char *argv[])
{
SDL_Thread *thread;
SDL_ThreadID threadID;int threadReturnValue;
"Simple SDL_CreateThread test:");
SDL_Log(
/* Simply create a thread */
"TestThread", (void *)NULL);
thread = SDL_CreateThread(TestThread,
if (NULL == thread) {
"SDL_CreateThread failed: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, 1);
exit(-
}
/* 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);"Thread returned value: %d", threadReturnValue);
SDL_Log(
return 0;
}