Fixed Bugzilla bug #205

Removed SDL_KillThread() from the API, as it isn't safe on many platforms.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403240
This commit is contained in:
Sam Lantinga 2008-11-24 00:18:42 +00:00
parent 35c71403d7
commit ad347d4a12
14 changed files with 15 additions and 106 deletions

View file

@ -62,19 +62,9 @@ main(int argc, char *argv[])
alive = 0;
SDL_WaitThread(thread, NULL);
alive = 1;
thread = SDL_CreateThread(ThreadFunc, "#2");
if (thread == NULL) {
fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
quit(1);
}
SDL_Delay(5 * 1000);
printf("Killing thread #2\n");
SDL_KillThread(thread);
alive = 1;
signal(SIGTERM, killed);
thread = SDL_CreateThread(ThreadFunc, "#3");
thread = SDL_CreateThread(ThreadFunc, "#2");
if (thread == NULL) {
fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
quit(1);

View file

@ -44,8 +44,9 @@ closemutex(int sig)
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 @@ Run(void *data)
{
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 @@ Run(void *data)
}
/* 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);
}