Remove CBitmapSurface.
[SDL.s60v3.git] / test / testhread.c
blobf87f3745c3c51bc6fc118541a3ffc4c2506a4482
2 /* Simple test of the SDL threading code */
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <signal.h>
8 #include "SDL.h"
9 #include "SDL_thread.h"
11 static int alive = 0;
13 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
14 static void quit(int rc)
16 SDL_Quit();
17 exit(rc);
20 int SDLCALL ThreadFunc(void *data)
22 printf("Started thread %s: My thread id is %u\n",
23 (char *)data, SDL_ThreadID());
24 while ( alive ) {
25 printf("Thread '%s' is alive!\n", (char *)data);
26 SDL_Delay(1*1000);
28 printf("Thread '%s' exiting!\n", (char *)data);
29 return(0);
32 static void killed(int sig)
34 printf("Killed with SIGTERM, waiting 5 seconds to exit\n");
35 SDL_Delay(5*1000);
36 alive = 0;
37 quit(0);
40 int main(int argc, char *argv[])
42 SDL_Thread *thread;
44 /* Load the SDL library */
45 if ( SDL_Init(0) < 0 ) {
46 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
47 return(1);
50 alive = 1;
51 thread = SDL_CreateThread(ThreadFunc, "#1");
52 if ( thread == NULL ) {
53 fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
54 quit(1);
56 SDL_Delay(5*1000);
57 printf("Waiting for thread #1\n");
58 alive = 0;
59 SDL_WaitThread(thread, NULL);
61 alive = 1;
62 thread = SDL_CreateThread(ThreadFunc, "#2");
63 if ( thread == NULL ) {
64 fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
65 quit(1);
67 SDL_Delay(5*1000);
68 printf("Killing thread #2\n");
69 SDL_KillThread(thread);
71 alive = 1;
72 signal(SIGTERM, killed);
73 thread = SDL_CreateThread(ThreadFunc, "#3");
74 if ( thread == NULL ) {
75 fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
76 quit(1);
78 raise(SIGTERM);
80 SDL_Quit(); /* Never reached */
81 return(0); /* Never reached */