test/torturethread.c
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1659 14717b52abc0
child 1668 4da1ee79c9af
     1.1 --- a/test/torturethread.c	Sun May 21 17:27:13 2006 +0000
     1.2 +++ b/test/torturethread.c	Sun May 28 13:04:16 2006 +0000
     1.3 @@ -14,78 +14,83 @@
     1.4  static char volatile time_for_threads_to_die[NUMTHREADS];
     1.5  
     1.6  /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
     1.7 -static void quit(int rc)
     1.8 +static void
     1.9 +quit (int rc)
    1.10  {
    1.11 -	SDL_Quit();
    1.12 -	exit(rc);
    1.13 +    SDL_Quit ();
    1.14 +    exit (rc);
    1.15  }
    1.16  
    1.17 -int SDLCALL SubThreadFunc(void *data) {
    1.18 -	while(! *(int volatile *)data) {
    1.19 -		; /*SDL_Delay(10);*/  /* do nothing */
    1.20 -	}
    1.21 -	return 0;
    1.22 +int SDLCALL
    1.23 +SubThreadFunc (void *data)
    1.24 +{
    1.25 +    while (!*(int volatile *) data) {
    1.26 +        ;                       /*SDL_Delay(10); *//* do nothing */
    1.27 +    }
    1.28 +    return 0;
    1.29  }
    1.30  
    1.31 -int SDLCALL ThreadFunc(void *data) {
    1.32 -	SDL_Thread *sub_threads[NUMTHREADS];
    1.33 -	int flags[NUMTHREADS];
    1.34 -	int i;
    1.35 -	int tid = (int)(uintptr_t)data;
    1.36 +int SDLCALL
    1.37 +ThreadFunc (void *data)
    1.38 +{
    1.39 +    SDL_Thread *sub_threads[NUMTHREADS];
    1.40 +    int flags[NUMTHREADS];
    1.41 +    int i;
    1.42 +    int tid = (int) (uintptr_t) data;
    1.43  
    1.44 -	fprintf(stderr, "Creating Thread %d\n", tid);
    1.45 +    fprintf (stderr, "Creating Thread %d\n", tid);
    1.46  
    1.47 -	for(i = 0; i < NUMTHREADS; i++) {
    1.48 -		flags[i] = 0;
    1.49 -		sub_threads[i] = SDL_CreateThread(SubThreadFunc, &flags[i]);
    1.50 -	}
    1.51 +    for (i = 0; i < NUMTHREADS; i++) {
    1.52 +        flags[i] = 0;
    1.53 +        sub_threads[i] = SDL_CreateThread (SubThreadFunc, &flags[i]);
    1.54 +    }
    1.55  
    1.56 -	printf("Thread '%d' waiting for signal\n", tid);
    1.57 -	while(time_for_threads_to_die[tid] != 1) {
    1.58 -		; /* do nothing */
    1.59 -	}
    1.60 +    printf ("Thread '%d' waiting for signal\n", tid);
    1.61 +    while (time_for_threads_to_die[tid] != 1) {
    1.62 +        ;                       /* do nothing */
    1.63 +    }
    1.64  
    1.65 -	printf("Thread '%d' sending signals to subthreads\n", tid);
    1.66 -	for(i = 0; i <  NUMTHREADS; i++) {
    1.67 -		flags[i] = 1;
    1.68 -		SDL_WaitThread(sub_threads[i], NULL);
    1.69 -	}
    1.70 +    printf ("Thread '%d' sending signals to subthreads\n", tid);
    1.71 +    for (i = 0; i < NUMTHREADS; i++) {
    1.72 +        flags[i] = 1;
    1.73 +        SDL_WaitThread (sub_threads[i], NULL);
    1.74 +    }
    1.75  
    1.76 -	printf("Thread '%d' exiting!\n", tid);
    1.77 +    printf ("Thread '%d' exiting!\n", tid);
    1.78  
    1.79 -	return 0;
    1.80 +    return 0;
    1.81  }
    1.82  
    1.83 -int main(int argc, char *argv[])
    1.84 +int
    1.85 +main (int argc, char *argv[])
    1.86  {
    1.87 -	SDL_Thread *threads[NUMTHREADS];
    1.88 -	int i;
    1.89 +    SDL_Thread *threads[NUMTHREADS];
    1.90 +    int i;
    1.91  
    1.92 -	/* Load the SDL library */
    1.93 -	if ( SDL_Init(0) < 0 ) {
    1.94 -		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
    1.95 -		return(1);
    1.96 -	}
    1.97 +    /* Load the SDL library */
    1.98 +    if (SDL_Init (0) < 0) {
    1.99 +        fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ());
   1.100 +        return (1);
   1.101 +    }
   1.102  
   1.103 -	signal(SIGSEGV, SIG_DFL);
   1.104 -	for(i = 0; i < NUMTHREADS; i++) {
   1.105 -		time_for_threads_to_die[i] = 0;
   1.106 -		threads[i] = SDL_CreateThread(ThreadFunc, (void *)(uintptr_t)i);
   1.107 -	
   1.108 -		if ( threads[i] == NULL ) {
   1.109 -			fprintf(stderr,
   1.110 -			"Couldn't create thread: %s\n", SDL_GetError());
   1.111 -			quit(1);
   1.112 -		}
   1.113 -	}
   1.114 +    signal (SIGSEGV, SIG_DFL);
   1.115 +    for (i = 0; i < NUMTHREADS; i++) {
   1.116 +        time_for_threads_to_die[i] = 0;
   1.117 +        threads[i] = SDL_CreateThread (ThreadFunc, (void *) (uintptr_t) i);
   1.118  
   1.119 -	for(i = 0; i < NUMTHREADS; i++) {
   1.120 -		time_for_threads_to_die[i] = 1;
   1.121 -	}
   1.122 +        if (threads[i] == NULL) {
   1.123 +            fprintf (stderr, "Couldn't create thread: %s\n", SDL_GetError ());
   1.124 +            quit (1);
   1.125 +        }
   1.126 +    }
   1.127  
   1.128 -	for(i = 0; i < NUMTHREADS; i++) {
   1.129 -		SDL_WaitThread(threads[i], NULL);
   1.130 -	}
   1.131 -	SDL_Quit();
   1.132 -	return(0);
   1.133 +    for (i = 0; i < NUMTHREADS; i++) {
   1.134 +        time_for_threads_to_die[i] = 1;
   1.135 +    }
   1.136 +
   1.137 +    for (i = 0; i < NUMTHREADS; i++) {
   1.138 +        SDL_WaitThread (threads[i], NULL);
   1.139 +    }
   1.140 +    SDL_Quit ();
   1.141 +    return (0);
   1.142  }