Mercurial > sdl-ios-xcode
diff test/testlock.c @ 3578:0d1b16ee0bca
Fixed bug #741
The thread ID is an unsigned long so it can hold pthread_t so people can do naughty things with it.
I'm going to be adding additional useful thread API functions, but this should prevent crashes in people's existing code on 64-bit architectures.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 16 Dec 2009 04:48:11 +0000 |
parents | 4436464c4f51 |
children |
line wrap: on
line diff
--- a/test/testlock.c Wed Dec 16 03:02:31 2009 +0000 +++ b/test/testlock.c Wed Dec 16 04:48:11 2009 +0000 @@ -11,7 +11,7 @@ #include "SDL_thread.h" static SDL_mutex *mutex = NULL; -static Uint32 mainthread; +static SDL_threadID mainthread; static SDL_Thread *threads[6]; static volatile int doterminate = 0; @@ -28,7 +28,7 @@ void printid(void) { - printf("Process %u: exiting\n", SDL_ThreadID()); + printf("Process %lu: exiting\n", SDL_ThreadID()); } void @@ -41,9 +41,9 @@ void closemutex(int sig) { - Uint32 id = SDL_ThreadID(); + SDL_threadID id = SDL_ThreadID(); int i; - printf("Process %u: Cleaning up...\n", id == mainthread ? 0 : id); + printf("Process %lu: Cleaning up...\n", id == mainthread ? 0 : id); doterminate = 1; for (i = 0; i < 6; ++i) SDL_WaitThread(threads[i], NULL); @@ -57,14 +57,14 @@ if (SDL_ThreadID() == mainthread) signal(SIGTERM, closemutex); while (!doterminate) { - printf("Process %u ready to work\n", SDL_ThreadID()); + printf("Process %lu ready to work\n", SDL_ThreadID()); if (SDL_mutexP(mutex) < 0) { fprintf(stderr, "Couldn't lock mutex: %s", SDL_GetError()); exit(1); } - printf("Process %u, working!\n", SDL_ThreadID()); + printf("Process %lu, working!\n", SDL_ThreadID()); SDL_Delay(1 * 1000); - printf("Process %u, done!\n", SDL_ThreadID()); + printf("Process %lu, done!\n", SDL_ThreadID()); if (SDL_mutexV(mutex) < 0) { fprintf(stderr, "Couldn't unlock mutex: %s", SDL_GetError()); exit(1); @@ -73,7 +73,7 @@ SDL_Delay(10); } if (SDL_ThreadID() == mainthread && doterminate) { - printf("Process %u: raising SIGTERM\n", SDL_ThreadID()); + printf("Process %lu: raising SIGTERM\n", SDL_ThreadID()); raise(SIGTERM); } return (0); @@ -98,7 +98,7 @@ } mainthread = SDL_ThreadID(); - printf("Main thread: %u\n", mainthread); + printf("Main thread: %lu\n", mainthread); atexit(printid); for (i = 0; i < maxproc; ++i) { if ((threads[i] = SDL_CreateThread(Run, NULL)) == NULL)