/[pcsx2_0.9.7]/trunk/3rdparty/SDL-1.3.0-5387/test/testhread.c
ViewVC logotype

Contents of /trunk/3rdparty/SDL-1.3.0-5387/test/testhread.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 401 - (show annotations) (download)
Fri Feb 25 17:31:09 2011 UTC (9 years, 9 months ago) by william
File MIME type: text/plain
File size: 1639 byte(s)
Auto Commited Import of: pcsx2-0.9.7-DEBUG (upstream: v0.9.7.4358 local: v0.9.7.313-latest) in ./trunk
1
2 /* Simple test of the SDL threading code */
3
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <signal.h>
7
8 #include "SDL.h"
9 #include "SDL_thread.h"
10
11 static int alive = 0;
12
13 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
14 static void
15 quit(int rc)
16 {
17 SDL_Quit();
18 exit(rc);
19 }
20
21 int SDLCALL
22 ThreadFunc(void *data)
23 {
24 printf("Started thread %s: My thread id is %lu\n",
25 (char *) data, SDL_ThreadID());
26 while (alive) {
27 printf("Thread '%s' is alive!\n", (char *) data);
28 SDL_Delay(1 * 1000);
29 }
30 printf("Thread '%s' exiting!\n", (char *) data);
31 return (0);
32 }
33
34 static void
35 killed(int sig)
36 {
37 printf("Killed with SIGTERM, waiting 5 seconds to exit\n");
38 SDL_Delay(5 * 1000);
39 alive = 0;
40 quit(0);
41 }
42
43 int
44 main(int argc, char *argv[])
45 {
46 SDL_Thread *thread;
47
48 /* Load the SDL library */
49 if (SDL_Init(0) < 0) {
50 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
51 return (1);
52 }
53
54 alive = 1;
55 thread = SDL_CreateThread(ThreadFunc, "#1");
56 if (thread == NULL) {
57 fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
58 quit(1);
59 }
60 SDL_Delay(5 * 1000);
61 printf("Waiting for thread #1\n");
62 alive = 0;
63 SDL_WaitThread(thread, NULL);
64
65 alive = 1;
66 signal(SIGTERM, killed);
67 thread = SDL_CreateThread(ThreadFunc, "#2");
68 if (thread == NULL) {
69 fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
70 quit(1);
71 }
72 raise(SIGTERM);
73
74 SDL_Quit(); /* Never reached */
75 return (0); /* Never reached */
76 }

  ViewVC Help
Powered by ViewVC 1.1.22