參考資訊:
https://wiki.libsdl.org/SDL_CreateThread
https://www.libsdl.org/release/SDL-1.2.15/docs/html/index.html
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, NULL); SDL_WaitThread(thread, &ret); printf("%s--\n", __func__); return 0; }
編譯、執行
$ gcc main.c -o main -lSDL -I/usr/include/SDL $ ./main main++ mythread++ mythread-- main--