thread: safely return NULL from thread_create() if threads not initialized

This commit is contained in:
Andrei Alexeyev 2024-05-13 03:30:19 +02:00
parent 83dfe8d5fa
commit dfa615bb77
No known key found for this signature in database
GPG key ID: 72D26128040B9690

View file

@ -134,6 +134,11 @@ static int SDLCALL sdlthread_entry(void *data) {
}
Thread *thread_create(const char *name, ThreadProc proc, void *userdata, ThreadPriority prio) {
if(UNLIKELY(!threads.main_id)) {
log_error("Thread subsystem is not initialized");
return NULL;
}
size_t nsize = strlen(name) + 1;
auto thrd = ALLOC_FLEX(Thread, nsize);
memcpy(thrd->name, name, nsize);