-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Labels
documentationRelated to documentation or commentsRelated to documentation or comments
Description
Describe the bug
It is found that the time interval is longer than the duration setting while using conditional_varaiable.wait_for(). If the duration is set 50ms, the actual waiting time is about 60ms..
Test case
#include <stdio.h>
#include <stdlib.h>
#include <thread>
#include <chrono>
#include <string.h>
#include <condition_variable>
#include <memory>
#include <fstream>
#include <list>
#include <vector>
#include <mutex>
std::mutex mtx;
std::condition_variable point_pack_condition;
using namespace std::chrono;
void wait()
{
int i = 0;
steady_clock::time_point last_time = steady_clock::now();
for (i = 0; i < 20; ++i) {
{
std::unique_lock<std::mutex> lock(mtx);
last_time = steady_clock::now();
printf("%d\n",point_pack_condition.wait_for(lock, milliseconds(50)));
printf("Delta time:%ld.\n", duration_cast<microseconds>(steady_clock::now() - last_time).count());
last_time = steady_clock::now();
}
printf("Finish save %d frame to lvx file.\n", i);
}
}
int main(int argc, const char *argv[]) {
std::thread t1(wait);
t1.join();
getchar();
}Expected behavior
The code tested on Ubuntu16.04 or win7 behaves as follows:

Version
Windows10
visual studio 2019
vc_tools:14.29.30133
Metadata
Metadata
Assignees
Labels
documentationRelated to documentation or commentsRelated to documentation or comments
