diff test/testlock.c @ 2779:4436464c4f51

Fixed Bugzilla bug #205 Removed SDL_KillThread() from the API, as it isn't safe on many platforms.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 24 Nov 2008 00:18:42 +0000
parents c121d94672cb
children 0d1b16ee0bca
line wrap: on
line diff
--- a/test/testlock.c	Sat Nov 22 06:59:22 2008 +0000
+++ b/test/testlock.c	Mon Nov 24 00:18:42 2008 +0000
@@ -44,8 +44,9 @@
     Uint32 id = SDL_ThreadID();
     int i;
     printf("Process %u:  Cleaning up...\n", id == mainthread ? 0 : id);
+    doterminate = 1;
     for (i = 0; i < 6; ++i)
-        SDL_KillThread(threads[i]);
+        SDL_WaitThread(threads[i], NULL);
     SDL_DestroyMutex(mutex);
     exit(sig);
 }
@@ -55,7 +56,7 @@
 {
     if (SDL_ThreadID() == mainthread)
         signal(SIGTERM, closemutex);
-    while (1) {
+    while (!doterminate) {
         printf("Process %u ready to work\n", SDL_ThreadID());
         if (SDL_mutexP(mutex) < 0) {
             fprintf(stderr, "Couldn't lock mutex: %s", SDL_GetError());
@@ -70,10 +71,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);
-        }
+    }
+    if (SDL_ThreadID() == mainthread && doterminate) {
+        printf("Process %u:  raising SIGTERM\n", SDL_ThreadID());
+        raise(SIGTERM);
     }
     return (0);
 }