程式語言 - Simple DirectMedia Layer (SDL) - v2.0 - C/C++ - Thread



參考資訊:
https://wiki.libsdl.org/FrontPage
https://wiki.libsdl.org/SDL_CreateThread

main.c

#include <stdio.h>
#include "SDL.h"

static int mythread(void *args)
{
    printf("%s++\n", __func__);
    SDL_Delay(1000);
    printf("%s--\n", __func__);
    return 0;
}

int main(int argc, char **argv)
{
    int ret = 0;

    printf("%s++\n", __func__);
    SDL_Thread *thread = SDL_CreateThread(mythread, "mythread", NULL);
    SDL_WaitThread(thread, &ret);
    printf("%s--\n", __func__);
    return 0;
}

編譯、執行

$ gcc main.c -o main -lSDL2 -I/usr/include/SDL2
$ ./main
    main++
    mythread++
    mythread--
    main--