summaryrefslogtreecommitdiff
path: root/src/bridges/pthread
diff options
context:
space:
mode:
Diffstat (limited to 'src/bridges/pthread')
-rw-r--r--src/bridges/pthread/thread_bridge.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/bridges/pthread/thread_bridge.c b/src/bridges/pthread/thread_bridge.c
index e014a3a..1cafacd 100644
--- a/src/bridges/pthread/thread_bridge.c
+++ b/src/bridges/pthread/thread_bridge.c
@@ -1,10 +1,20 @@
#ifdef USE_THREAD
#include <bridges/pthread/thread_bridge.h>
+#include <pthread.h>
+#include <errno.h>
pthread_t run_job_in_thread(ff_thread_job *job) {
pthread_t thread;
- pthread_create(&thread, NULL, ff_thread_wrapper, job);
+ int r = pthread_create(&thread, NULL, ff_thread_wrapper, job);
+ if (r != 0) {
+ // pthread_create failed; return an invalid thread value (0) to signal error
+ return (pthread_t)0;
+ }
+
+ // Detach the thread to avoid requiring callers to join it. If you want join
+ // semantics, consider changing the API to return an error and an out pthread_t.
+ pthread_detach(thread);
return thread;
}