Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android pthread_cond_timedwait_单调问题等待~30ms,即使超时值为0_Android_Android Ndk - Fatal编程技术网

Android pthread_cond_timedwait_单调问题等待~30ms,即使超时值为0

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

我正在使用ndk-8编译以下代码。运行应用程序时,即使传递的超时值为0,timedwait也会消耗约30毫秒的等待时间

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单调