I have a 12 hour clock and a 24 hour clock. I need to have a thread that sleeps one second then calls the method to update by a second. I first tried the getc and unget c functions but have been told that I need to thread sleep for one second and then call method to update it by a second. Below is the snippet of code. Everytime I give user input to add an hour, or minute, and seconds to the clocks it also adds a second to the clocks at the same time. I don't think this is what is supposed to be happening. Any suggestions on how I can accomplish this task is appreciated. I have many tabs open adn the more I research the more confused I seem to get.
Note "Fixed pending release" is somewhat misleading because the fix would affect the Standard library's binary interface and therefore will not be released until a sane decision about binary compatibility is reached.
As mbozzi says above, sleep_for() will suspend execution of the thread for at least the specified duration. In practice, the suspension time could be longer - possibly much longer - depending upon other executing threads, priorities etc.
Windows, Linus etc are not real-time OS's so any timing is only approx.
Often if a suspension delay is appropriate (as opposed to using synchronization) then the exact actual suspension time isn't critical. However, when you want to update say a clock then it might well be. The longer the suspension, the more likely the exact suspension time is more than that specified. After some hours you could easily be a few seconds adrift.
In cases like this, I suggest that one approach is to obtain the new system time after execution has resumed.
Obtain current time;
Another approach is (as pseudo):
1 2 3 4 5
Obtain the current time (t1);
Sleep(0); //which causes the thread to relinquish the remainder of its time slice to any other thread that is ready to run
Obtain the current time (t2);
} Until t2 - t1 is that required.