test/testthread.c
changeset 7391 a29895dc5e9a
parent 5969 3a041d215edc
child 7393 358696c354a8
     1.1 --- a/test/testthread.c	Tue Jul 09 12:58:54 2013 -0700
     1.2 +++ b/test/testthread.c	Wed Jul 10 02:32:04 2013 -0700
     1.3 @@ -19,6 +19,7 @@
     1.4  #include "SDL.h"
     1.5  #include "SDL_thread.h"
     1.6  
     1.7 +static SDL_TLSID tls;
     1.8  static int alive = 0;
     1.9  
    1.10  /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    1.11 @@ -32,8 +33,9 @@
    1.12  int SDLCALL
    1.13  ThreadFunc(void *data)
    1.14  {
    1.15 -    printf("Started thread %s: My thread id is %lu\n",
    1.16 -           (char *) data, SDL_ThreadID());
    1.17 +    SDL_TLSSet(tls, "baby thread");
    1.18 +    printf("Started thread %s: My thread id is %lu, thread data = %s\n",
    1.19 +           (char *) data, SDL_ThreadID(), (const char *)SDL_TLSGet(tls));
    1.20      while (alive) {
    1.21          printf("Thread '%s' is alive!\n", (char *) data);
    1.22          SDL_Delay(1 * 1000);
    1.23 @@ -62,6 +64,11 @@
    1.24          return (1);
    1.25      }
    1.26  
    1.27 +    tls = SDL_TLSCreate();
    1.28 +    SDL_assert(tls);
    1.29 +    SDL_TLSSet(tls, "main thread");
    1.30 +    printf("Main thread data initially: %s\n", (const char *)SDL_TLSGet(tls));
    1.31 +
    1.32      alive = 1;
    1.33      thread = SDL_CreateThread(ThreadFunc, "One", "#1");
    1.34      if (thread == NULL) {
    1.35 @@ -73,6 +80,8 @@
    1.36      alive = 0;
    1.37      SDL_WaitThread(thread, NULL);
    1.38  
    1.39 +    printf("Main thread data finally: %s\n", (const char *)SDL_TLSGet(tls));
    1.40 +
    1.41      alive = 1;
    1.42      signal(SIGTERM, killed);
    1.43      thread = SDL_CreateThread(ThreadFunc, "Two", "#2");