1.3 API CHANGE: Add support for naming threads.
2 Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
13 /* Simple test of the SDL threading code and error handling */
20 #include "SDL_thread.h"
24 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
33 ThreadFunc(void *data)
35 /* Set the child thread error string */
36 SDL_SetError("Thread %s (%lu) had a problem: %s",
37 (char *) data, SDL_ThreadID(), "nevermind");
39 printf("Thread '%s' is alive!\n", (char *) data);
42 printf("Child thread error string: %s\n", SDL_GetError());
47 main(int argc, char *argv[])
51 /* Load the SDL library */
52 if (SDL_Init(0) < 0) {
53 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
57 /* Set the error value for the main thread */
58 SDL_SetError("No worries");
61 thread = SDL_CreateThread(ThreadFunc, NULL, "#1");
63 fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
67 printf("Waiting for thread #1\n");
69 SDL_WaitThread(thread, NULL);
71 printf("Main thread error string: %s\n", SDL_GetError());