Wiki Page Content

Differences between revisions 7 and 8
Revision 7 as of 2011-03-05 15:45:33
Size: 2366
Editor: Paul Walters
Revision 8 as of 2011-03-18 21:20:34
Size: 2366
Editor: SheenaSmith
Comment: camelcase pragma change, fix category link
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:
#pragma disable-camelcase #pragma camelcase off
Line 78: Line 78:
[[CategoryAPI]], CategoryThread [[CategoryAPI]], [[CategoryThread]]



Use this function to wait for a thread to finish.


void SDL_WaitThread(SDL_Thread* thread,
                    int*        status)

Function Parameters


The SDL_Thread point that was returned from the SDL_CreateThread call that started this thread


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());

           // 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;

                printf( "\nThread counter: %d", cnt);

        // Return the final value to the SDL_WaitThread function above
        return cnt;


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.

CategoryAPI, CategoryThread

None: SDL_WaitThread (last edited 2018-12-12 14:53:52 by RyanGordon)

Please include your contact information if you'd like to receive a reply.