2 /* Simple test of the SDL threading code */
9 #include "SDL_thread.h"
13 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
14 static void quit(int rc)
20 int SDLCALL ThreadFunc(void *data)
22 printf("Started thread %s: My thread id is %u\n",
23 (char *)data, SDL_ThreadID());
25 printf("Thread '%s' is alive!\n", (char *)data);
28 printf("Thread '%s' exiting!\n", (char *)data);
32 static void killed(int sig)
34 printf("Killed with SIGTERM, waiting 5 seconds to exit\n");
40 int main(int argc, char *argv[])
44 /* Load the SDL library */
45 if ( SDL_Init(0) < 0 ) {
46 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
51 thread = SDL_CreateThread(ThreadFunc, "#1");
52 if ( thread == NULL ) {
53 fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
57 printf("Waiting for thread #1\n");
59 SDL_WaitThread(thread, NULL);
62 thread = SDL_CreateThread(ThreadFunc, "#2");
63 if ( thread == NULL ) {
64 fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
68 printf("Killing thread #2\n");
69 SDL_KillThread(thread);
72 signal(SIGTERM, killed);
73 thread = SDL_CreateThread(ThreadFunc, "#3");
74 if ( thread == NULL ) {
75 fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
80 SDL_Quit(); /* Never reached */
81 return(0); /* Never reached */