b24c2a743b181481454816222301d0b832b5ccc9 angie Fri Oct 28 15:11:02 2022 -0700 Add pthreadJoin for getting a thread worker function's return value. diff --git src/lib/pthreadWrap.c src/lib/pthreadWrap.c index 66bf02a..7ee4ee6 100644 --- src/lib/pthreadWrap.c +++ src/lib/pthreadWrap.c @@ -34,30 +34,37 @@ /* Create a thread or squawk and die. */ { int err = pthread_create(thread, attr, start_routine, arg); perr("pthread_create", err); } boolean pthreadMayCreate(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg) /* Create a thread. Warn and return FALSE if there is a problem. */ { int err = pthread_create(thread, attr, start_routine, arg); pwarn("pthread_create", err); return err == 0; } +void pthreadJoin(pthread_t *thread, void **retVal) +/* Wait for thread to complete and optionally get its return value, or die. */ +{ +int err = pthread_join(*thread, retVal); +perr("pthread_join", err); +} + void pthreadMutexInit(pthread_mutex_t *mutex) /* Initialize mutex or die trying */ { int err = pthread_mutex_init(mutex, NULL); perr("pthread_mutex_init", err); } void pthreadMutexDestroy(pthread_mutex_t *mutex) /* Free up mutex. */ { int err = pthread_mutex_destroy(mutex); perr("pthread_mutex_destroy", err); } void pthreadMutexLock(pthread_mutex_t *mutex)