test/testlock.c
changeset 1769 290b5baf2fca
parent 1151 be9c9c8f6d53
child 1662 782fd950bd46
child 1895 c121d94672cb
--- a/test/testlock.c	Fri May 05 05:50:26 2006 +0000
+++ b/test/testlock.c	Sun May 07 03:40:06 2006 +0000
@@ -5,7 +5,6 @@
 
 #include <signal.h>
 #include <stdio.h>
-#include <stdlib.h>
 
 #include "SDL.h"
 #include "SDL_mutex.h"
@@ -14,6 +13,7 @@
 static SDL_mutex *mutex = NULL;
 static Uint32 mainthread;
 static SDL_Thread *threads[6];
+static volatile int doterminate = 0;
 
 /*
  * SDL_Quit() shouldn't be used with atexit() directly because
@@ -31,8 +31,8 @@
 	
 void terminate(int sig)
 {
-	printf("Process %u:  raising SIGTERM\n", SDL_ThreadID());
-	raise(SIGTERM);
+	signal(SIGINT, terminate);
+	doterminate = 1;
 }
 void closemutex(int sig)
 {
@@ -44,7 +44,7 @@
 	SDL_DestroyMutex(mutex);
 	exit(sig);
 }
-int Run(void *data)
+int SDLCALL Run(void *data)
 {
 	if ( SDL_ThreadID() == mainthread )
 		signal(SIGTERM, closemutex);
@@ -63,6 +63,10 @@
 		}
 		/* If this sleep isn't done, then threads may starve */
 		SDL_Delay(10);
+		if (SDL_ThreadID() == mainthread && doterminate) {
+			printf("Process %u:  raising SIGTERM\n", SDL_ThreadID());
+			raise(SIGTERM);
+		}
 	}
 	return(0);
 }