|
Size: 2123
Comment: Added sample code
|
Size: 2366
Comment:
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 17: | Line 17: |
| ||'''thread''' ||^the thread to wait for^ || ||'''status''' ||^the pointer to receive the return code???^; see [[#Remarks|Remarks]] for details || <<Color2(green,Is '''status''' an exception to the 'pointer rule'?)>> |
||'''thread''' ||The SDL_Thread point that was returned from the SDL_CreateThread call that started this thread || ||'''status''' ||Pointer to an integer that will receive the value returned from the thread function by its 'return', see [[#Remarks|Remarks]] for details || |
| Line 47: | Line 44: |
// Wait for the thread to complete. The thread functions return code will // be placed in the "threadReturnValue" variable when it completes. // |
|
| Line 65: | Line 66: |
| // Return the final value to the SDL_WaitThread function above | |
| Line 67: | Line 69: |
| Line 70: | Line 71: |
| The return code for the thread function is placed in the area pointed to by '''status''', if '''status''' is not NULL. | The return code for the thread function is placed in the area pointed to by '''status''', if '''status''' is not NULL. The return code is the value returned by the 'return' call in the thread function. This can be a 'status' on the thread, or the result of a computation the thread was created to perform. |
| Line 72: | Line 73: |
| <<Color2(green,Should anything be included here (or in Return Value?) that indicates what the "return code" might be? Seems like maybe 1 for waiting 0 for done -1 for error? Why is that not a Return Value? Just because it fills a pointer with it?)>> |
DRAFT |
SDL_WaitThread
Use this function to wait for a thread to finish.
Syntax
void SDL_WaitThread(SDL_Thread* thread,
int* status)
Function Parameters
thread |
The SDL_Thread point that was returned from the SDL_CreateThread call that started this thread |
status |
Pointer to an integer that will receive the value returned from the thread function by its 'return', see Remarks for details |
Code Examples
Toggle line numbers
#include <stdio.h>
#include <SDL_thread.h>
#include <SDL_timer.h>
int TestThread( void *ptr );
int main(int argc, char *argv[])
{
SDL_Thread *thread;
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());
else
{
// Wait for the thread to complete. The thread functions return code will
// be placed in the "threadReturnValue" variable when it completes.
//
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 the final value to the SDL_WaitThread function above
return cnt;
}
Remarks
The return code for the thread function is placed in the area pointed to by status, if status is not NULL. The return code is the value returned by the 'return' call in the thread function. This can be a 'status' on the thread, or the result of a computation the thread was created to perform.
