34
34
ThreadFunc(void *data)
36
36
SDL_TLSSet(tls, "baby thread", NULL);
37
printf("Started thread %s: My thread id is %lu, thread data = %s\n",
37
SDL_Log("Started thread %s: My thread id is %lu, thread data = %s\n",
38
38
(char *) data, SDL_ThreadID(), (const char *)SDL_TLSGet(tls));
40
printf("Thread '%s' is alive!\n", (char *) data);
40
SDL_Log("Thread '%s' is alive!\n", (char *) data);
41
41
SDL_Delay(1 * 1000);
43
printf("Thread '%s' exiting!\n", (char *) data);
43
SDL_Log("Thread '%s' exiting!\n", (char *) data);
50
printf("Killed with SIGTERM, waiting 5 seconds to exit\n");
50
SDL_Log("Killed with SIGTERM, waiting 5 seconds to exit\n");
51
51
SDL_Delay(5 * 1000);
59
59
SDL_Thread *thread;
61
/* Enable standard application logging */
62
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
61
64
/* Load the SDL library */
62
65
if (SDL_Init(0) < 0) {
63
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
66
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
67
70
tls = SDL_TLSCreate();
69
72
SDL_TLSSet(tls, "main thread", NULL);
70
printf("Main thread data initially: %s\n", (const char *)SDL_TLSGet(tls));
73
SDL_Log("Main thread data initially: %s\n", (const char *)SDL_TLSGet(tls));
73
76
thread = SDL_CreateThread(ThreadFunc, "One", "#1");
74
77
if (thread == NULL) {
75
fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
78
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError());
78
81
SDL_Delay(5 * 1000);
79
printf("Waiting for thread #1\n");
82
SDL_Log("Waiting for thread #1\n");
81
84
SDL_WaitThread(thread, NULL);
83
printf("Main thread data finally: %s\n", (const char *)SDL_TLSGet(tls));
86
SDL_Log("Main thread data finally: %s\n", (const char *)SDL_TLSGet(tls));
86
89
signal(SIGTERM, killed);
87
90
thread = SDL_CreateThread(ThreadFunc, "Two", "#2");
88
91
if (thread == NULL) {
89
fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
92
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError());