|
Size: 1091
Comment: Updated descriptions
|
Size: 2272
Comment: Finally got it to take the code sample
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 26: | Line 26: |
#include <stdio.h> #include <SDL_thread.h> #include <SDL_timer.h> int TestThread( void *ptr ); 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, (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 1; } // 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; } |
DRAFT |
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 desired/specified thread to query |
Return Value
Returns the ID of the specified thread. 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.
If the passed-in SDL_Thread pointer is NULL, this function will always return an SDL_threadID of zero.
Code Examples
#include <stdio.h>
#include <SDL_thread.h>
#include <SDL_timer.h>
int TestThread( void *ptr );
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, (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 1;
}
// 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;
}
Remarks
If the SDL thread pointer passed to this function is NULL, this function will return the SDL_ThreadID of the current thread.
