diff options
-rw-r--r-- | src/thread.c | 11 | ||||
-rw-r--r-- | src/thread.h | 1 |
2 files changed, 12 insertions, 0 deletions
diff --git a/src/thread.c b/src/thread.c index fdc8112..b84ee66 100644 --- a/src/thread.c +++ b/src/thread.c @@ -53,6 +53,17 @@ void thread_join(thread_t thread) #endif } +int thread_alive(thread_t thread) +{ + if (!thread) + return 0; +#ifdef WIN32 + return WaitForSingleObject(thread, 0) == WAIT_TIMEOUT; +#else + return pthread_kill(thread, 0) == 0; +#endif +} + void mutex_init(mutex_t* mutex) { #ifdef WIN32 diff --git a/src/thread.h b/src/thread.h index bd53c5b..11e789a 100644 --- a/src/thread.h +++ b/src/thread.h @@ -46,6 +46,7 @@ typedef void* (*thread_func_t)(void* data); int thread_new(thread_t* thread, thread_func_t thread_func, void* data); void thread_free(thread_t thread); void thread_join(thread_t thread); +int thread_alive(thread_t thread); void mutex_init(mutex_t* mutex); void mutex_destroy(mutex_t* mutex); |