comparison test/testhread.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
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 14 static void
15 quit (int rc) 15 quit(int rc)
16 { 16 {
17 SDL_Quit (); 17 SDL_Quit();
18 exit (rc); 18 exit(rc);
19 } 19 }
20 20
21 int SDLCALL 21 int SDLCALL
22 ThreadFunc (void *data) 22 ThreadFunc(void *data)
23 { 23 {
24 printf ("Started thread %s: My thread id is %u\n", 24 printf("Started thread %s: My thread id is %u\n",
25 (char *) data, SDL_ThreadID ()); 25 (char *) data, SDL_ThreadID());
26 while (alive) { 26 while (alive) {
27 printf ("Thread '%s' is alive!\n", (char *) data); 27 printf("Thread '%s' is alive!\n", (char *) data);
28 SDL_Delay (1 * 1000); 28 SDL_Delay(1 * 1000);
29 } 29 }
30 printf ("Thread '%s' exiting!\n", (char *) data); 30 printf("Thread '%s' exiting!\n", (char *) data);
31 return (0); 31 return (0);
32 } 32 }
33 33
34 static void 34 static void
35 killed (int sig) 35 killed(int sig)
36 { 36 {
37 printf ("Killed with SIGTERM, waiting 5 seconds to exit\n"); 37 printf("Killed with SIGTERM, waiting 5 seconds to exit\n");
38 SDL_Delay (5 * 1000); 38 SDL_Delay(5 * 1000);
39 alive = 0; 39 alive = 0;
40 quit (0); 40 quit(0);
41 } 41 }
42 42
43 int 43 int
44 main (int argc, char *argv[]) 44 main(int argc, char *argv[])
45 { 45 {
46 SDL_Thread *thread; 46 SDL_Thread *thread;
47 47
48 /* Load the SDL library */ 48 /* Load the SDL library */
49 if (SDL_Init (0) < 0) { 49 if (SDL_Init(0) < 0) {
50 fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ()); 50 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
51 return (1); 51 return (1);
52 } 52 }
53 53
54 alive = 1; 54 alive = 1;
55 thread = SDL_CreateThread (ThreadFunc, "#1"); 55 thread = SDL_CreateThread(ThreadFunc, "#1");
56 if (thread == NULL) { 56 if (thread == NULL) {
57 fprintf (stderr, "Couldn't create thread: %s\n", SDL_GetError ()); 57 fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
58 quit (1); 58 quit(1);
59 } 59 }
60 SDL_Delay (5 * 1000); 60 SDL_Delay(5 * 1000);
61 printf ("Waiting for thread #1\n"); 61 printf("Waiting for thread #1\n");
62 alive = 0; 62 alive = 0;
63 SDL_WaitThread (thread, NULL); 63 SDL_WaitThread(thread, NULL);
64 64
65 alive = 1; 65 alive = 1;
66 thread = SDL_CreateThread (ThreadFunc, "#2"); 66 thread = SDL_CreateThread(ThreadFunc, "#2");
67 if (thread == NULL) { 67 if (thread == NULL) {
68 fprintf (stderr, "Couldn't create thread: %s\n", SDL_GetError ()); 68 fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
69 quit (1); 69 quit(1);
70 } 70 }
71 SDL_Delay (5 * 1000); 71 SDL_Delay(5 * 1000);
72 printf ("Killing thread #2\n"); 72 printf("Killing thread #2\n");
73 SDL_KillThread (thread); 73 SDL_KillThread(thread);
74 74
75 alive = 1; 75 alive = 1;
76 signal (SIGTERM, killed); 76 signal(SIGTERM, killed);
77 thread = SDL_CreateThread (ThreadFunc, "#3"); 77 thread = SDL_CreateThread(ThreadFunc, "#3");
78 if (thread == NULL) { 78 if (thread == NULL) {
79 fprintf (stderr, "Couldn't create thread: %s\n", SDL_GetError ()); 79 fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
80 quit (1); 80 quit(1);
81 } 81 }
82 raise (SIGTERM); 82 raise(SIGTERM);
83 83
84 SDL_Quit (); /* Never reached */ 84 SDL_Quit(); /* Never reached */
85 return (0); /* Never reached */ 85 return (0); /* Never reached */
86 } 86 }