comparison test/testsem.c @ 1495:1dd8bf30a109

Might have fixed 64-bit issues. :)
author Sam Lantinga <slouken@libsdl.org>
date Sat, 11 Mar 2006 22:54:12 +0000
parents 4d3bb026cd16
children d5298e8f22b3
comparison
equal deleted inserted replaced
1494:4da1926c287c 1495:1dd8bf30a109
13 static SDL_sem *sem; 13 static SDL_sem *sem;
14 int alive = 1; 14 int alive = 1;
15 15
16 int ThreadFunc(void *data) 16 int ThreadFunc(void *data)
17 { 17 {
18 uintptr_t threadnum = (uintptr_t)data;
18 while ( alive ) { 19 while ( alive ) {
19 SDL_SemWait(sem); 20 SDL_SemWait(sem);
20 fprintf(stderr, "Thread number %d has got the semaphore (value = %d)!\n", (int)data, SDL_SemValue(sem)); 21 fprintf(stderr, "Thread number %d has got the semaphore (value = %d)!\n", threadnum, SDL_SemValue(sem));
21 SDL_Delay(200); 22 SDL_Delay(200);
22 SDL_SemPost(sem); 23 SDL_SemPost(sem);
23 fprintf(stderr, "Thread number %d has released the semaphore (value = %d)!\n", (int)data, SDL_SemValue(sem)); 24 fprintf(stderr, "Thread number %d has released the semaphore (value = %d)!\n", threadnum, SDL_SemValue(sem));
24 SDL_Delay(1); /* For the scheduler */ 25 SDL_Delay(1); /* For the scheduler */
25 } 26 }
26 printf("Thread number %d exiting.\n", (int)data); 27 printf("Thread number %d exiting.\n", threadnum);
27 return 0; 28 return 0;
28 } 29 }
29 30
30 static void killed(int sig) 31 static void killed(int sig)
31 { 32 {
33 } 34 }
34 35
35 int main(int argc, char **argv) 36 int main(int argc, char **argv)
36 { 37 {
37 SDL_Thread *threads[NUM_THREADS]; 38 SDL_Thread *threads[NUM_THREADS];
38 int i, init_sem; 39 uintptr_t i;
40 int init_sem;
39 41
40 if(argc < 2) { 42 if(argc < 2) {
41 fprintf(stderr,"Usage: %s init_value\n", argv[0]); 43 fprintf(stderr,"Usage: %s init_value\n", argv[0]);
42 return(1); 44 return(1);
43 } 45 }