|
Size: 1819
Comment: Sorted functions in example to remove a prototype.
|
← Revision 18 as of 2017-03-11 22:48:55 ⇥
Size: 1797
Comment: Fixed includes and comments in example.
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 24: | Line 24: |
| #include "SDL_thread.h" #include "SDL_timer.h" |
#include "SDL.h" |
| Line 48: | Line 47: |
| // Simply create a thread | /* Simply create a thread */ |
| Line 56: | Line 55: |
| // Retrieve the ID for the newly launched thread | /* Retrieve the ID for the newly launched thread */ |
| Line 59: | Line 58: |
| // Wait for the thread to complete and get the return code | /* Wait for the thread to complete and get the return code */ |
SDL_GetThreadID
Use this function to get the thread identifier for the specified thread.
Contents
Syntax
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.
Code Examples
#include <stdio.h>
#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) {
printf("\nThread counter: %d", cnt);
SDL_Delay(50);
}
return cnt;
}
int main(int argc, char *argv[])
{
SDL_Thread *thread;
SDL_threadID threadID;
int threadReturnValue;
printf("\nSimple SDL_CreateThread test:");
/* Simply create a thread */
thread = SDL_CreateThread(TestThread, "TestThread", (void *)NULL);
if (NULL == thread) {
printf("\nSDL_CreateThread failed: %s\n", SDL_GetError());
exit(-1);
}
/* 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);
printf("\nThread returned value: %d", threadReturnValue);
return 0;
}
Remarks
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.
