Mercurial > sdl-ios-xcode
comparison test/testhread.c @ 1662:782fd950bd46 SDL-1.3
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.
The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce
The headers are being converted to automatically generate doxygen documentation.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 28 May 2006 13:04:16 +0000 |
parents | 14717b52abc0 |
children | 4da1ee79c9af |
comparison
equal
deleted
inserted
replaced
1661:281d3f4870e5 | 1662:782fd950bd46 |
---|---|
9 #include "SDL_thread.h" | 9 #include "SDL_thread.h" |
10 | 10 |
11 static int alive = 0; | 11 static int alive = 0; |
12 | 12 |
13 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ | 13 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ |
14 static void quit(int rc) | 14 static void |
15 quit (int rc) | |
15 { | 16 { |
16 SDL_Quit(); | 17 SDL_Quit (); |
17 exit(rc); | 18 exit (rc); |
18 } | 19 } |
19 | 20 |
20 int SDLCALL ThreadFunc(void *data) | 21 int SDLCALL |
22 ThreadFunc (void *data) | |
21 { | 23 { |
22 printf("Started thread %s: My thread id is %u\n", | 24 printf ("Started thread %s: My thread id is %u\n", |
23 (char *)data, SDL_ThreadID()); | 25 (char *) data, SDL_ThreadID ()); |
24 while ( alive ) { | 26 while (alive) { |
25 printf("Thread '%s' is alive!\n", (char *)data); | 27 printf ("Thread '%s' is alive!\n", (char *) data); |
26 SDL_Delay(1*1000); | 28 SDL_Delay (1 * 1000); |
27 } | 29 } |
28 printf("Thread '%s' exiting!\n", (char *)data); | 30 printf ("Thread '%s' exiting!\n", (char *) data); |
29 return(0); | 31 return (0); |
30 } | 32 } |
31 | 33 |
32 static void killed(int sig) | 34 static void |
35 killed (int sig) | |
33 { | 36 { |
34 printf("Killed with SIGTERM, waiting 5 seconds to exit\n"); | 37 printf ("Killed with SIGTERM, waiting 5 seconds to exit\n"); |
35 SDL_Delay(5*1000); | 38 SDL_Delay (5 * 1000); |
36 alive = 0; | 39 alive = 0; |
37 quit(0); | 40 quit (0); |
38 } | 41 } |
39 | 42 |
40 int main(int argc, char *argv[]) | 43 int |
44 main (int argc, char *argv[]) | |
41 { | 45 { |
42 SDL_Thread *thread; | 46 SDL_Thread *thread; |
43 | 47 |
44 /* Load the SDL library */ | 48 /* Load the SDL library */ |
45 if ( SDL_Init(0) < 0 ) { | 49 if (SDL_Init (0) < 0) { |
46 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); | 50 fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ()); |
47 return(1); | 51 return (1); |
48 } | 52 } |
49 | 53 |
50 alive = 1; | 54 alive = 1; |
51 thread = SDL_CreateThread(ThreadFunc, "#1"); | 55 thread = SDL_CreateThread (ThreadFunc, "#1"); |
52 if ( thread == NULL ) { | 56 if (thread == NULL) { |
53 fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError()); | 57 fprintf (stderr, "Couldn't create thread: %s\n", SDL_GetError ()); |
54 quit(1); | 58 quit (1); |
55 } | 59 } |
56 SDL_Delay(5*1000); | 60 SDL_Delay (5 * 1000); |
57 printf("Waiting for thread #1\n"); | 61 printf ("Waiting for thread #1\n"); |
58 alive = 0; | 62 alive = 0; |
59 SDL_WaitThread(thread, NULL); | 63 SDL_WaitThread (thread, NULL); |
60 | 64 |
61 alive = 1; | 65 alive = 1; |
62 thread = SDL_CreateThread(ThreadFunc, "#2"); | 66 thread = SDL_CreateThread (ThreadFunc, "#2"); |
63 if ( thread == NULL ) { | 67 if (thread == NULL) { |
64 fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError()); | 68 fprintf (stderr, "Couldn't create thread: %s\n", SDL_GetError ()); |
65 quit(1); | 69 quit (1); |
66 } | 70 } |
67 SDL_Delay(5*1000); | 71 SDL_Delay (5 * 1000); |
68 printf("Killing thread #2\n"); | 72 printf ("Killing thread #2\n"); |
69 SDL_KillThread(thread); | 73 SDL_KillThread (thread); |
70 | 74 |
71 alive = 1; | 75 alive = 1; |
72 signal(SIGTERM, killed); | 76 signal (SIGTERM, killed); |
73 thread = SDL_CreateThread(ThreadFunc, "#3"); | 77 thread = SDL_CreateThread (ThreadFunc, "#3"); |
74 if ( thread == NULL ) { | 78 if (thread == NULL) { |
75 fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError()); | 79 fprintf (stderr, "Couldn't create thread: %s\n", SDL_GetError ()); |
76 quit(1); | 80 quit (1); |
77 } | 81 } |
78 raise(SIGTERM); | 82 raise (SIGTERM); |
79 | 83 |
80 SDL_Quit(); /* Never reached */ | 84 SDL_Quit (); /* Never reached */ |
81 return(0); /* Never reached */ | 85 return (0); /* Never reached */ |
82 } | 86 } |