test/testerror.c
changeset 0 74212992fb08
child 1151 be9c9c8f6d53
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/testerror.c	Thu Apr 26 16:45:43 2001 +0000
     1.3 @@ -0,0 +1,54 @@
     1.4 +
     1.5 +/* Simple test of the SDL threading code and error handling */
     1.6 +
     1.7 +#include <stdio.h>
     1.8 +#include <stdlib.h>
     1.9 +#include <signal.h>
    1.10 +
    1.11 +#include "SDL.h"
    1.12 +#include "SDL_thread.h"
    1.13 +
    1.14 +static int alive = 0;
    1.15 +
    1.16 +int ThreadFunc(void *data)
    1.17 +{
    1.18 +	/* Set the child thread error string */
    1.19 +	SDL_SetError("Thread %s (%d) had a problem: %s",
    1.20 +			(char *)data, SDL_ThreadID(), "nevermind");
    1.21 +	while ( alive ) {
    1.22 +		printf("Thread '%s' is alive!\n", (char *)data);
    1.23 +		SDL_Delay(1*1000);
    1.24 +	}
    1.25 +	printf("Child thread error string: %s\n", SDL_GetError());
    1.26 +	return(0);
    1.27 +}
    1.28 +
    1.29 +int main(int argc, char *argv[])
    1.30 +{
    1.31 +	SDL_Thread *thread;
    1.32 +
    1.33 +	/* Load the SDL library */
    1.34 +	if ( SDL_Init(0) < 0 ) {
    1.35 +		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
    1.36 +		exit(1);
    1.37 +	}
    1.38 +	atexit(SDL_Quit);
    1.39 +
    1.40 +	/* Set the error value for the main thread */
    1.41 +	SDL_SetError("No worries");
    1.42 +
    1.43 +	alive = 1;
    1.44 +	thread = SDL_CreateThread(ThreadFunc, "#1");
    1.45 +	if ( thread == NULL ) {
    1.46 +		fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
    1.47 +		exit(1);
    1.48 +	}
    1.49 +	SDL_Delay(5*1000);
    1.50 +	printf("Waiting for thread #1\n");
    1.51 +	alive = 0;
    1.52 +	SDL_WaitThread(thread, NULL);
    1.53 +
    1.54 +	printf("Main thread error string: %s\n", SDL_GetError());
    1.55 +
    1.56 +	return(0);
    1.57 +}