comparison test/testerror.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents 290b5baf2fca
children 0d1b16ee0bca
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
9 #include "SDL_thread.h" 9 #include "SDL_thread.h"
10 10
11 static int alive = 0; 11 static int alive = 0;
12 12
13 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ 13 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
14 static void quit(int rc) 14 static void
15 quit(int rc)
15 { 16 {
16 SDL_Quit(); 17 SDL_Quit();
17 exit(rc); 18 exit(rc);
18 } 19 }
19 20
20 int SDLCALL ThreadFunc(void *data) 21 int SDLCALL
22 ThreadFunc(void *data)
21 { 23 {
22 /* Set the child thread error string */ 24 /* Set the child thread error string */
23 SDL_SetError("Thread %s (%d) had a problem: %s", 25 SDL_SetError("Thread %s (%d) had a problem: %s",
24 (char *)data, SDL_ThreadID(), "nevermind"); 26 (char *) data, SDL_ThreadID(), "nevermind");
25 while ( alive ) { 27 while (alive) {
26 printf("Thread '%s' is alive!\n", (char *)data); 28 printf("Thread '%s' is alive!\n", (char *) data);
27 SDL_Delay(1*1000); 29 SDL_Delay(1 * 1000);
28 } 30 }
29 printf("Child thread error string: %s\n", SDL_GetError()); 31 printf("Child thread error string: %s\n", SDL_GetError());
30 return(0); 32 return (0);
31 } 33 }
32 34
33 int main(int argc, char *argv[]) 35 int
36 main(int argc, char *argv[])
34 { 37 {
35 SDL_Thread *thread; 38 SDL_Thread *thread;
36 39
37 /* Load the SDL library */ 40 /* Load the SDL library */
38 if ( SDL_Init(0) < 0 ) { 41 if (SDL_Init(0) < 0) {
39 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); 42 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
40 return(1); 43 return (1);
41 } 44 }
42 45
43 /* Set the error value for the main thread */ 46 /* Set the error value for the main thread */
44 SDL_SetError("No worries"); 47 SDL_SetError("No worries");
45 48
46 alive = 1; 49 alive = 1;
47 thread = SDL_CreateThread(ThreadFunc, "#1"); 50 thread = SDL_CreateThread(ThreadFunc, "#1");
48 if ( thread == NULL ) { 51 if (thread == NULL) {
49 fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError()); 52 fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
50 quit(1); 53 quit(1);
51 } 54 }
52 SDL_Delay(5*1000); 55 SDL_Delay(5 * 1000);
53 printf("Waiting for thread #1\n"); 56 printf("Waiting for thread #1\n");
54 alive = 0; 57 alive = 0;
55 SDL_WaitThread(thread, NULL); 58 SDL_WaitThread(thread, NULL);
56 59
57 printf("Main thread error string: %s\n", SDL_GetError()); 60 printf("Main thread error string: %s\n", SDL_GetError());
58 61
59 SDL_Quit(); 62 SDL_Quit();
60 return(0); 63 return (0);
61 } 64 }