test/testhread.c
changeset 1151 be9c9c8f6d53
parent 0 74212992fb08
child 1659 14717b52abc0
     1.1 --- a/test/testhread.c	Wed Sep 28 06:38:22 2005 +0000
     1.2 +++ b/test/testhread.c	Wed Sep 28 11:36:20 2005 +0000
     1.3 @@ -10,6 +10,13 @@
     1.4  
     1.5  static int alive = 0;
     1.6  
     1.7 +/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
     1.8 +static void quit(int rc)
     1.9 +{
    1.10 +	SDL_Quit();
    1.11 +	exit(rc);
    1.12 +}
    1.13 +
    1.14  int ThreadFunc(void *data)
    1.15  {
    1.16  	printf("Started thread %s: My thread id is %u\n",
    1.17 @@ -27,7 +34,7 @@
    1.18  	printf("Killed with SIGTERM, waiting 5 seconds to exit\n");
    1.19  	SDL_Delay(5*1000);
    1.20  	alive = 0;
    1.21 -	exit(0);
    1.22 +	quit(0);
    1.23  }
    1.24  
    1.25  int main(int argc, char *argv[])
    1.26 @@ -37,15 +44,14 @@
    1.27  	/* Load the SDL library */
    1.28  	if ( SDL_Init(0) < 0 ) {
    1.29  		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
    1.30 -		exit(1);
    1.31 +		return(1);
    1.32  	}
    1.33 -	atexit(SDL_Quit);
    1.34  
    1.35  	alive = 1;
    1.36  	thread = SDL_CreateThread(ThreadFunc, "#1");
    1.37  	if ( thread == NULL ) {
    1.38  		fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
    1.39 -		exit(1);
    1.40 +		quit(1);
    1.41  	}
    1.42  	SDL_Delay(5*1000);
    1.43  	printf("Waiting for thread #1\n");
    1.44 @@ -56,7 +62,7 @@
    1.45  	thread = SDL_CreateThread(ThreadFunc, "#2");
    1.46  	if ( thread == NULL ) {
    1.47  		fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
    1.48 -		exit(1);
    1.49 +		quit(1);
    1.50  	}
    1.51  	SDL_Delay(5*1000);
    1.52  	printf("Killing thread #2\n");
    1.53 @@ -67,9 +73,10 @@
    1.54  	thread = SDL_CreateThread(ThreadFunc, "#3");
    1.55  	if ( thread == NULL ) {
    1.56  		fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
    1.57 -		exit(1);
    1.58 +		quit(1);
    1.59  	}
    1.60  	raise(SIGTERM);
    1.61  
    1.62 +	SDL_Quit();	/* Never reached */
    1.63  	return(0);	/* Never reached */
    1.64  }