comparison 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
comparison
equal deleted inserted replaced
2778:38dfc890ee6b 2779:4436464c4f51
42 closemutex(int sig) 42 closemutex(int sig)
43 { 43 {
44 Uint32 id = SDL_ThreadID(); 44 Uint32 id = SDL_ThreadID();
45 int i; 45 int i;
46 printf("Process %u: Cleaning up...\n", id == mainthread ? 0 : id); 46 printf("Process %u: Cleaning up...\n", id == mainthread ? 0 : id);
47 doterminate = 1;
47 for (i = 0; i < 6; ++i) 48 for (i = 0; i < 6; ++i)
48 SDL_KillThread(threads[i]); 49 SDL_WaitThread(threads[i], NULL);
49 SDL_DestroyMutex(mutex); 50 SDL_DestroyMutex(mutex);
50 exit(sig); 51 exit(sig);
51 } 52 }
52 53
53 int SDLCALL 54 int SDLCALL
54 Run(void *data) 55 Run(void *data)
55 { 56 {
56 if (SDL_ThreadID() == mainthread) 57 if (SDL_ThreadID() == mainthread)
57 signal(SIGTERM, closemutex); 58 signal(SIGTERM, closemutex);
58 while (1) { 59 while (!doterminate) {
59 printf("Process %u ready to work\n", SDL_ThreadID()); 60 printf("Process %u ready to work\n", SDL_ThreadID());
60 if (SDL_mutexP(mutex) < 0) { 61 if (SDL_mutexP(mutex) < 0) {
61 fprintf(stderr, "Couldn't lock mutex: %s", SDL_GetError()); 62 fprintf(stderr, "Couldn't lock mutex: %s", SDL_GetError());
62 exit(1); 63 exit(1);
63 } 64 }
68 fprintf(stderr, "Couldn't unlock mutex: %s", SDL_GetError()); 69 fprintf(stderr, "Couldn't unlock mutex: %s", SDL_GetError());
69 exit(1); 70 exit(1);
70 } 71 }
71 /* If this sleep isn't done, then threads may starve */ 72 /* If this sleep isn't done, then threads may starve */
72 SDL_Delay(10); 73 SDL_Delay(10);
73 if (SDL_ThreadID() == mainthread && doterminate) { 74 }
74 printf("Process %u: raising SIGTERM\n", SDL_ThreadID()); 75 if (SDL_ThreadID() == mainthread && doterminate) {
75 raise(SIGTERM); 76 printf("Process %u: raising SIGTERM\n", SDL_ThreadID());
76 } 77 raise(SIGTERM);
77 } 78 }
78 return (0); 79 return (0);
79 } 80 }
80 81
81 int 82 int