From f9b529b75982902c9b31ee59fe73e2c56b8ba237 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Sun, 5 Nov 2017 16:14:32 +0100 Subject: thread: Add 'thread_alive' helper --- src/thread.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/thread.c') 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 -- cgit v1.1-32-gdbae