diff --git a/src/blackbox_render.c b/src/blackbox_render.c index de2434f..89796bc 100644 --- a/src/blackbox_render.c +++ b/src/blackbox_render.c @@ -984,7 +984,6 @@ void saveSurfaceAsync(cairo_surface_t *surface, int logIndex, int outputFrameInd pngRenderingSemCreated = true; } - thread_t thread; pngRenderingTask_t *task = (pngRenderingTask_t*) malloc(sizeof(*task)); task->surface = surface; @@ -994,7 +993,7 @@ void saveSurfaceAsync(cairo_surface_t *surface, int logIndex, int outputFrameInd // Reserve a slot in the rendering pool... semaphore_wait(&pngRenderingSem); - thread_create(&thread, pngRenderThread, task); + thread_create_detached(pngRenderThread, task); } void waitForFramesToSave() diff --git a/src/platform.c b/src/platform.c index 3c9f74d..1cdc4cc 100644 --- a/src/platform.c +++ b/src/platform.c @@ -40,17 +40,22 @@ } #endif -void thread_create(thread_t *thread, threadRoutine_t threadFunc, void *data) +void thread_create_detached(threadRoutine_t threadFunc, void *data) { + thread_t thread; + #if defined(WIN32) win32ThreadFuncWrapper_t *wrap = malloc(sizeof(*wrap)); wrap->threadFunc = threadFunc; wrap->data = data; - *thread = CreateThread(NULL, 0, win32ThreadFuncUnwrap, wrap, 0, NULL); + thread = CreateThread(NULL, 0, win32ThreadFuncUnwrap, wrap, 0, NULL); + + // Detach from thread immediately + CloseHandle(thread); #else - pthread_create(thread, &pthreadCreateDetached, threadFunc, data); + pthread_create(&thread, &pthreadCreateDetached, threadFunc, data); #endif } diff --git a/src/platform.h b/src/platform.h index 816ec1f..fdd737c 100644 --- a/src/platform.h +++ b/src/platform.h @@ -52,7 +52,7 @@ typedef struct fileMapping_t { typedef void*(*threadRoutine_t)(void *data); -void thread_create(thread_t *thread, threadRoutine_t threadFunc, void *data); +void thread_create_detached(threadRoutine_t threadFunc, void *data); bool mmap_file(fileMapping_t *mapping, int fd); void munmap_file(fileMapping_t *mapping);