comparison test/torturethread.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
13 13
14 static char volatile time_for_threads_to_die[NUMTHREADS]; 14 static char volatile time_for_threads_to_die[NUMTHREADS];
15 15
16 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ 16 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
17 static void 17 static void
18 quit (int rc) 18 quit(int rc)
19 { 19 {
20 SDL_Quit (); 20 SDL_Quit();
21 exit (rc); 21 exit(rc);
22 } 22 }
23 23
24 int SDLCALL 24 int SDLCALL
25 SubThreadFunc (void *data) 25 SubThreadFunc(void *data)
26 { 26 {
27 while (!*(int volatile *) data) { 27 while (!*(int volatile *) data) {
28 ; /*SDL_Delay(10); *//* do nothing */ 28 ; /*SDL_Delay(10); *//* do nothing */
29 } 29 }
30 return 0; 30 return 0;
31 } 31 }
32 32
33 int SDLCALL 33 int SDLCALL
34 ThreadFunc (void *data) 34 ThreadFunc(void *data)
35 { 35 {
36 SDL_Thread *sub_threads[NUMTHREADS]; 36 SDL_Thread *sub_threads[NUMTHREADS];
37 int flags[NUMTHREADS]; 37 int flags[NUMTHREADS];
38 int i; 38 int i;
39 int tid = (int) (uintptr_t) data; 39 int tid = (int) (uintptr_t) data;
40 40
41 fprintf (stderr, "Creating Thread %d\n", tid); 41 fprintf(stderr, "Creating Thread %d\n", tid);
42 42
43 for (i = 0; i < NUMTHREADS; i++) { 43 for (i = 0; i < NUMTHREADS; i++) {
44 flags[i] = 0; 44 flags[i] = 0;
45 sub_threads[i] = SDL_CreateThread (SubThreadFunc, &flags[i]); 45 sub_threads[i] = SDL_CreateThread(SubThreadFunc, &flags[i]);
46 } 46 }
47 47
48 printf ("Thread '%d' waiting for signal\n", tid); 48 printf("Thread '%d' waiting for signal\n", tid);
49 while (time_for_threads_to_die[tid] != 1) { 49 while (time_for_threads_to_die[tid] != 1) {
50 ; /* do nothing */ 50 ; /* do nothing */
51 } 51 }
52 52
53 printf ("Thread '%d' sending signals to subthreads\n", tid); 53 printf("Thread '%d' sending signals to subthreads\n", tid);
54 for (i = 0; i < NUMTHREADS; i++) { 54 for (i = 0; i < NUMTHREADS; i++) {
55 flags[i] = 1; 55 flags[i] = 1;
56 SDL_WaitThread (sub_threads[i], NULL); 56 SDL_WaitThread(sub_threads[i], NULL);
57 } 57 }
58 58
59 printf ("Thread '%d' exiting!\n", tid); 59 printf("Thread '%d' exiting!\n", tid);
60 60
61 return 0; 61 return 0;
62 } 62 }
63 63
64 int 64 int
65 main (int argc, char *argv[]) 65 main(int argc, char *argv[])
66 { 66 {
67 SDL_Thread *threads[NUMTHREADS]; 67 SDL_Thread *threads[NUMTHREADS];
68 int i; 68 int i;
69 69
70 /* Load the SDL library */ 70 /* Load the SDL library */
71 if (SDL_Init (0) < 0) { 71 if (SDL_Init(0) < 0) {
72 fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ()); 72 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
73 return (1); 73 return (1);
74 } 74 }
75 75
76 signal (SIGSEGV, SIG_DFL); 76 signal(SIGSEGV, SIG_DFL);
77 for (i = 0; i < NUMTHREADS; i++) { 77 for (i = 0; i < NUMTHREADS; i++) {
78 time_for_threads_to_die[i] = 0; 78 time_for_threads_to_die[i] = 0;
79 threads[i] = SDL_CreateThread (ThreadFunc, (void *) (uintptr_t) i); 79 threads[i] = SDL_CreateThread(ThreadFunc, (void *) (uintptr_t) i);
80 80
81 if (threads[i] == NULL) { 81 if (threads[i] == NULL) {
82 fprintf (stderr, "Couldn't create thread: %s\n", SDL_GetError ()); 82 fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
83 quit (1); 83 quit(1);
84 } 84 }
85 } 85 }
86 86
87 for (i = 0; i < NUMTHREADS; i++) { 87 for (i = 0; i < NUMTHREADS; i++) {
88 time_for_threads_to_die[i] = 1; 88 time_for_threads_to_die[i] = 1;
89 } 89 }
90 90
91 for (i = 0; i < NUMTHREADS; i++) { 91 for (i = 0; i < NUMTHREADS; i++) {
92 SDL_WaitThread (threads[i], NULL); 92 SDL_WaitThread(threads[i], NULL);
93 } 93 }
94 SDL_Quit (); 94 SDL_Quit();
95 return (0); 95 return (0);
96 } 96 }