See the truth of Qt from the source code 1-sleep

void QThread::usleep ( unsigned long usecs ) [static protected]
Causes the current thread to sleep for usecs microseconds.
See also sleep() and msleep().
Causes this thread to sleep for several microseconds

The truth under Windows

void QThread::usleep(unsigned long usecs)
{
    ::Sleep((usecs / 1000) + 1);
}

    You can see that the accuracy of usleep under Windows is the accuracy of Sleep, which is the millisecond level, and it has no effect if it is less than the millisecond level.

The truth under Unix

static void thread_sleep(struct timespec *ti)
{
    pthread_mutex_t mtx;
    pthread_cond_t cnd;

    pthread_mutex_init(&mtx, 0);
    pthread_cond_init(&cnd, 0);

    pthread_mutex_lock(&mtx);
    (void) pthread_cond_timedwait(&cnd, &mtx, ti);
    pthread_mutex_unlock(&mtx);

    pthread_cond_destroy(&cnd);
    pthread_mutex_destroy(&mtx);
}

  Qt uses pthread under Unix/Linux

pthread_cond_timedwait

  Let the waiting condition never be satisfied and then wait for the timeout, similar to using select to implement the sleep function

  The author does not know much about the details of linux, and the accuracy that can be achieved here depends entirely on the timeout accuracy provided by pthread.

 

   


{{o.name}}
{{m.name}}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324142156&siteId=291194637