Android pthread_cond_timedwait_单调问题等待~30ms,即使超时值为0
我正在使用ndk-8编译以下代码。运行应用程序时,即使传递的超时值为0,timedwait也会消耗约30毫秒的等待时间Android pthread_cond_timedwait_单调问题等待~30ms,即使超时值为0,android,android-ndk,Android,Android Ndk,我正在使用ndk-8编译以下代码。运行应用程序时,即使传递的超时值为0,timedwait也会消耗约30毫秒的等待时间 int TimedWait(uint32_t timeoutInMs) { struct timespec monotonicTime; int retval = clock_gettime(CLOCK_MONOTONIC, &monotonicTime); monotonicTime.tv_sec += timeoutInMs
int TimedWait(uint32_t timeoutInMs)
{
struct timespec monotonicTime;
int retval = clock_gettime(CLOCK_MONOTONIC, &monotonicTime);
monotonicTime.tv_sec += timeoutInMs / 1000;
monotonicTime.tv_nsec += (timeoutInMs % 1000) * 1000000L;
if (monotonicTime.tv_nsec >= 1000000000L)
{
monotonicTime.tv_sec += monotonicTime.tv_nsec / 1000000000L;
monotonicTime.tv_nsec = monotonicTime.tv_nsec % 1000000000L;
}
pthread_cond_timedwait_monotonic_np(&v_Cond, &v_Mutex, &monotonicTime);
}
你试过用
pthread\u cond\u timedwait()
代替吗?谢谢Serhio,pthread\u cond\u timedwait()有效,前提是我必须使用CLOCK\u REALTIME而不是CLOCK\u单调。你试过用pthread\u cond\u timedwait()
代替吗?谢谢Serhio,pthread\u cond\u timedwait()有效,前提是我必须使用CLOCK\u REALTIME而不是CLOCK\u单调