LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-24-2021, 12:43 AM   #1
Mahesh C
LQ Newbie
 
Registered: Feb 2021
Posts: 2

Rep: Reputation: Disabled
Wait time delay with condition_variable in C++


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:
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
Mahesh

Last edited by Mahesh C; 02-25-2021 at 08:17 AM.
 
Old 02-24-2021, 01:06 AM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206
Welcome to LQ and the Programming forum!

Please wrap your code snippets in [CODE]...[/CODE] tags to preserve formatting and help to make it easier for others to read it. You may type those yourself or follow the Advanced edit option and click the # tool button at top of the edit box.

Without knowing anything about the device which is working differently it will be difficult for anyone to offer much help.

Is that device very busy? Is the RTC of the device stable? What type of device is this and what operating system is running on the device, what is it doing?

Please provide as much relevant information as you think would be helpful to others to understand your problem.
 
Old 02-24-2021, 05:11 AM   #3
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
Any other instance of the same programme running simultaneously?
 
Old 02-24-2021, 05:25 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,039

Rep: Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347
is this a VM ?
 
Old 02-25-2021, 08:28 AM   #5
Mahesh C
LQ Newbie
 
Registered: Feb 2021
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thanks Astrogeek,

Added the code under code blocks.
Mentioned sample code tried on various linux based embedded devices. On particular linux based variant only we are observing this delay.
Device is neither busy nor doing any time consuming work. but still delay is observed.
RTC is unstable means are you pointing to hardware issue ?



thanks
Mahesh
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need a boot delay to wait for network interfaces jason_not Linux - Networking 2 12-19-2012 11:39 AM
[SOLVED] Java: Delay (sleep, wait or whatever) within the ActionPerformed function rm_-rf_windows Programming 4 10-19-2012 05:21 PM
how to understand user time, sys time, wait time, idle time of CPU guixingyi Linux - Server 1 08-24-2010 10:10 AM
I download then wait and download and wait... jsheffie SUSE / openSUSE 1 11-04-2005 04:43 PM
How do you set the keyboard wait-until-repeat delay? deanbrown3d Linux - Newbie 2 06-18-2004 09:35 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration