Вопрос

Is there a pthreads API call that can do something simlar to pthread_join() but with a timeout? I'm looking for a function that is similar to the Windows WaitForSingleObject(HANDLE handle, int timeout) function. I know that there's a pthread_timedjoin() call, but that's only available on certain version's of Linux (definitely not in Android).

Это было полезно?

Решение

No, there's no standard API for a timed pthread_join(), and not one available in the bionic C library used by Android. Though looking at the bionic source code, it'd be very easy for them to implement the pthread_timedjoin_np() API as available in glibc.

What you can do is to modify your thread to signal a pthread_cond_t when it's finished and about to exit. Your other thread that wants to wait on that thread does a pthread_cond_timedwait() on the condition variable.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top