test/testhread.c
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1659 14717b52abc0
child 1668 4da1ee79c9af
     1.1 --- a/test/testhread.c	Sun May 21 17:27:13 2006 +0000
     1.2 +++ b/test/testhread.c	Sun May 28 13:04:16 2006 +0000
     1.3 @@ -11,72 +11,76 @@
     1.4  static int alive = 0;
     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 ThreadFunc(void *data)
    1.18 +int SDLCALL
    1.19 +ThreadFunc (void *data)
    1.20  {
    1.21 -	printf("Started thread %s: My thread id is %u\n",
    1.22 -				(char *)data, SDL_ThreadID());
    1.23 -	while ( alive ) {
    1.24 -		printf("Thread '%s' is alive!\n", (char *)data);
    1.25 -		SDL_Delay(1*1000);
    1.26 -	}
    1.27 -	printf("Thread '%s' exiting!\n", (char *)data);
    1.28 -	return(0);
    1.29 +    printf ("Started thread %s: My thread id is %u\n",
    1.30 +            (char *) data, SDL_ThreadID ());
    1.31 +    while (alive) {
    1.32 +        printf ("Thread '%s' is alive!\n", (char *) data);
    1.33 +        SDL_Delay (1 * 1000);
    1.34 +    }
    1.35 +    printf ("Thread '%s' exiting!\n", (char *) data);
    1.36 +    return (0);
    1.37  }
    1.38  
    1.39 -static void killed(int sig)
    1.40 +static void
    1.41 +killed (int sig)
    1.42  {
    1.43 -	printf("Killed with SIGTERM, waiting 5 seconds to exit\n");
    1.44 -	SDL_Delay(5*1000);
    1.45 -	alive = 0;
    1.46 -	quit(0);
    1.47 +    printf ("Killed with SIGTERM, waiting 5 seconds to exit\n");
    1.48 +    SDL_Delay (5 * 1000);
    1.49 +    alive = 0;
    1.50 +    quit (0);
    1.51  }
    1.52  
    1.53 -int main(int argc, char *argv[])
    1.54 +int
    1.55 +main (int argc, char *argv[])
    1.56  {
    1.57 -	SDL_Thread *thread;
    1.58 +    SDL_Thread *thread;
    1.59  
    1.60 -	/* Load the SDL library */
    1.61 -	if ( SDL_Init(0) < 0 ) {
    1.62 -		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
    1.63 -		return(1);
    1.64 -	}
    1.65 +    /* Load the SDL library */
    1.66 +    if (SDL_Init (0) < 0) {
    1.67 +        fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ());
    1.68 +        return (1);
    1.69 +    }
    1.70  
    1.71 -	alive = 1;
    1.72 -	thread = SDL_CreateThread(ThreadFunc, "#1");
    1.73 -	if ( thread == NULL ) {
    1.74 -		fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
    1.75 -		quit(1);
    1.76 -	}
    1.77 -	SDL_Delay(5*1000);
    1.78 -	printf("Waiting for thread #1\n");
    1.79 -	alive = 0;
    1.80 -	SDL_WaitThread(thread, NULL);
    1.81 +    alive = 1;
    1.82 +    thread = SDL_CreateThread (ThreadFunc, "#1");
    1.83 +    if (thread == NULL) {
    1.84 +        fprintf (stderr, "Couldn't create thread: %s\n", SDL_GetError ());
    1.85 +        quit (1);
    1.86 +    }
    1.87 +    SDL_Delay (5 * 1000);
    1.88 +    printf ("Waiting for thread #1\n");
    1.89 +    alive = 0;
    1.90 +    SDL_WaitThread (thread, NULL);
    1.91  
    1.92 -	alive = 1;
    1.93 -	thread = SDL_CreateThread(ThreadFunc, "#2");
    1.94 -	if ( thread == NULL ) {
    1.95 -		fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
    1.96 -		quit(1);
    1.97 -	}
    1.98 -	SDL_Delay(5*1000);
    1.99 -	printf("Killing thread #2\n");
   1.100 -	SDL_KillThread(thread);
   1.101 +    alive = 1;
   1.102 +    thread = SDL_CreateThread (ThreadFunc, "#2");
   1.103 +    if (thread == NULL) {
   1.104 +        fprintf (stderr, "Couldn't create thread: %s\n", SDL_GetError ());
   1.105 +        quit (1);
   1.106 +    }
   1.107 +    SDL_Delay (5 * 1000);
   1.108 +    printf ("Killing thread #2\n");
   1.109 +    SDL_KillThread (thread);
   1.110  
   1.111 -	alive = 1;
   1.112 -	signal(SIGTERM, killed);
   1.113 -	thread = SDL_CreateThread(ThreadFunc, "#3");
   1.114 -	if ( thread == NULL ) {
   1.115 -		fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
   1.116 -		quit(1);
   1.117 -	}
   1.118 -	raise(SIGTERM);
   1.119 +    alive = 1;
   1.120 +    signal (SIGTERM, killed);
   1.121 +    thread = SDL_CreateThread (ThreadFunc, "#3");
   1.122 +    if (thread == NULL) {
   1.123 +        fprintf (stderr, "Couldn't create thread: %s\n", SDL_GetError ());
   1.124 +        quit (1);
   1.125 +    }
   1.126 +    raise (SIGTERM);
   1.127  
   1.128 -	SDL_Quit();	/* Never reached */
   1.129 -	return(0);	/* Never reached */
   1.130 +    SDL_Quit ();                /* Never reached */
   1.131 +    return (0);                 /* Never reached */
   1.132  }