Create a new thread with a default stack size.
extern DECLSPEC SDL_Thread *SDLCALL
const char *name, void *data); SDL_CreateThread(SDL_ThreadFunction fn,
fn | the SDL_ThreadFunction function to call in the new thread |
name | the name of the thread |
data | a pointer that is passed to fn |
Returns an opaque pointer to the new thread object on success, NULL if the new thread could not be created; call SDL_GetError() for more information.
This is equivalent to calling:
0, data); SDL_CreateThreadWithStackSize(fn, name,
This function is available since SDL 3.0.0.
#include "SDL.h"
/* Very simple thread - counts 0 to 9 delaying 50ms between increments */
static int TestThread(void *ptr)
{int cnt;
for (cnt = 0; cnt < 10; ++cnt) {
"Thread counter: %d\n", cnt);
SDL_Log(50);
SDL_Delay(
}
return cnt;
}
int main(int argc, char *argv[])
{
SDL_Thread *thread;int threadReturnValue;
"Simple SDL_CreateThread test:\n");
SDL_Log(
/* Simply create a thread */
"TestThread", (void *)NULL);
thread = SDL_CreateThread(TestThread,
if (NULL == thread) {
"SDL_CreateThread failed: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, else {
}
SDL_WaitThread(thread, &threadReturnValue);"Thread returned value: %d\n", threadReturnValue);
SDL_Log(
}
return 0;
}
Output:
Simple SDL_CreateThread test:0
Thread counter: 1
Thread counter: 2
Thread counter: 3
Thread counter: 4
Thread counter: 5
Thread counter: 6
Thread counter: 7
Thread counter: 8
Thread counter: 9
Thread counter: 10 Thread returned value: