Article 5EJYG Wait time delay with condition_variable in C++

Wait time delay with condition_variable in C++

by
Mahesh C
from LinuxQuestions.org on (#5EJYG)
Dear All,

In C++ project for linux, we have used the condition_variable to wait in a loop. Sometimes we are observing delay in wake up. e.g. we have set the interval of 10mins, getting the delay of ~2mins in between. here are the observations:
Wait until: [22-2-2021 19:0:58]
Wait until: [22-2-2021 19:10:58]
Wait until: [22-2-2021 19:20:58]
Wait until: [22-2-2021 19:30:58]
Wait until: [22-2-2021 19:42:20]

Wait until: [22-2-2021 19:52:20]

it is suppose to wake up 19:40:58 but woke up at 19:42:20. Could anybody help me to understand why this delay is occurring?

This is observed on only particular device variant, for rest of devices same code working as expected.

Please find the sample code:
auto nowp = std::chrono::system_clock::now();

while(true)
{
std::unique_lock<std::mutex> lock(cv_mtx);
cv.wait_until(lock, nowp, [](){ return false;});
nowp += std::chrono::minutes(delay);
std::cout<<"Wait until: "<<get_formatted_time(nowp)<<std::endl;
}

Thanks
Maheshlatest?d=yIl2AUoC8zA latest?i=027BfAneTTI:XlV-gFvDeh0:F7zBnMy latest?i=027BfAneTTI:XlV-gFvDeh0:V_sGLiP latest?d=qj6IDK7rITs latest?i=027BfAneTTI:XlV-gFvDeh0:gIN9vFw027BfAneTTI
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments