Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
64 lines (52 loc) · 1.38 KB

testerror.c

File metadata and controls

64 lines (52 loc) · 1.38 KB
 
Apr 26, 2001
Apr 26, 2001
1
2
3
4
5
6
7
8
9
10
11
12
/* Simple test of the SDL threading code and error handling */
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include "SDL.h"
#include "SDL_thread.h"
static int alive = 0;
Sep 28, 2005
Sep 28, 2005
13
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
May 28, 2006
May 28, 2006
14
static void
May 29, 2006
May 29, 2006
15
quit(int rc)
Sep 28, 2005
Sep 28, 2005
16
{
May 29, 2006
May 29, 2006
17
18
SDL_Quit();
exit(rc);
Sep 28, 2005
Sep 28, 2005
19
20
}
May 28, 2006
May 28, 2006
21
int SDLCALL
May 29, 2006
May 29, 2006
22
ThreadFunc(void *data)
Apr 26, 2001
Apr 26, 2001
23
{
May 28, 2006
May 28, 2006
24
/* Set the child thread error string */
May 29, 2006
May 29, 2006
25
26
SDL_SetError("Thread %s (%d) had a problem: %s",
(char *) data, SDL_ThreadID(), "nevermind");
May 28, 2006
May 28, 2006
27
while (alive) {
May 29, 2006
May 29, 2006
28
29
printf("Thread '%s' is alive!\n", (char *) data);
SDL_Delay(1 * 1000);
May 28, 2006
May 28, 2006
30
}
May 29, 2006
May 29, 2006
31
printf("Child thread error string: %s\n", SDL_GetError());
May 28, 2006
May 28, 2006
32
return (0);
Apr 26, 2001
Apr 26, 2001
33
34
}
May 28, 2006
May 28, 2006
35
int
May 29, 2006
May 29, 2006
36
main(int argc, char *argv[])
Apr 26, 2001
Apr 26, 2001
37
{
May 28, 2006
May 28, 2006
38
39
40
SDL_Thread *thread;
/* Load the SDL library */
May 29, 2006
May 29, 2006
41
42
if (SDL_Init(0) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
May 28, 2006
May 28, 2006
43
44
45
46
return (1);
}
/* Set the error value for the main thread */
May 29, 2006
May 29, 2006
47
SDL_SetError("No worries");
May 28, 2006
May 28, 2006
48
49
alive = 1;
May 29, 2006
May 29, 2006
50
thread = SDL_CreateThread(ThreadFunc, "#1");
May 28, 2006
May 28, 2006
51
if (thread == NULL) {
May 29, 2006
May 29, 2006
52
53
fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
quit(1);
May 28, 2006
May 28, 2006
54
}
May 29, 2006
May 29, 2006
55
56
SDL_Delay(5 * 1000);
printf("Waiting for thread #1\n");
May 28, 2006
May 28, 2006
57
alive = 0;
May 29, 2006
May 29, 2006
58
SDL_WaitThread(thread, NULL);
May 28, 2006
May 28, 2006
59
May 29, 2006
May 29, 2006
60
printf("Main thread error string: %s\n", SDL_GetError());
May 28, 2006
May 28, 2006
61
May 29, 2006
May 29, 2006
62
SDL_Quit();
May 28, 2006
May 28, 2006
63
return (0);
Apr 26, 2001
Apr 26, 2001
64
}