c++ - clock_gettime() returns about 1-2ms inaccuracy every 50-100ms (Debian wheezy on Virtualbox) -
i had closely related thread while ago here.
however, replacing cin.ignore()
usleep(50e3)
. not report every 50ms. clock reports
time passed: s: 0 ms: 50 time passed: s: 0 ms: 101 time passed: s: 0 ms: 152 time passed: s: 0 ms: 202 time passed: s: 0 ms: 252 time passed: s: 0 ms: 303 time passed: s: 0 ms: 353 time passed: s: 0 ms: 403 time passed: s: 0 ms: 454 time passed: s: 0 ms: 504 time passed: s: 0 ms: 554 time passed: s: 0 ms: 605 time passed: s: 0 ms: 657 time passed: s: 0 ms: 708 time passed: s: 0 ms: 758 time passed: s: 0 ms: 808 time passed: s: 0 ms: 862 time passed: s: 0 ms: 915 time passed: s: 0 ms: 965 time passed: s: 1 ms: 15 time passed: s: 1 ms: 66 time passed: s: 1 ms: 116 time passed: s: 1 ms: 169 time passed: s: 1 ms: 221 time passed: s: 1 ms: 271 time passed: s: 1 ms: 322 time passed: s: 1 ms: 372 time passed: s: 1 ms: 423 time passed: s: 1 ms: 473 time passed: s: 1 ms: 524 time passed: s: 1 ms: 574 time passed: s: 1 ms: 625 time passed: s: 1 ms: 676 time passed: s: 1 ms: 727 time passed: s: 1 ms: 778 time passed: s: 1 ms: 833 time passed: s: 1 ms: 883 time passed: s: 1 ms: 935 time passed: s: 1 ms: 986 time passed: s: 2 ms: 37 time passed: s: 2 ms: 91 time passed: s: 2 ms: 142 time passed: s: 2 ms: 192 time passed: s: 2 ms: 243 time passed: s: 2 ms: 294 time passed: s: 2 ms: 346 time passed: s: 2 ms: 396 time passed: s: 2 ms: 450 time passed: s: 2 ms: 501 time passed: s: 2 ms: 552 time passed: s: 2 ms: 602 time passed: s: 2 ms: 652 time passed: s: 2 ms: 703 time passed: s: 2 ms: 753 time passed: s: 2 ms: 804 time passed: s: 2 ms: 855 time passed: s: 2 ms: 906 time passed: s: 2 ms: 956 time passed: s: 3 ms: 7 time passed: s: 3 ms: 57 time passed: s: 3 ms: 107 time passed: s: 3 ms: 158 time passed: s: 3 ms: 208 time passed: s: 3 ms: 258 time passed: s: 3 ms: 315 time passed: s: 3 ms: 365 time passed: s: 3 ms: 416 time passed: s: 3 ms: 466 time passed: s: 3 ms: 517 time passed: s: 3 ms: 567 time passed: s: 3 ms: 618 time passed: s: 3 ms: 668 time passed: s: 3 ms: 719 time passed: s: 3 ms: 769 time passed: s: 3 ms: 824 time passed: s: 3 ms: 875 time passed: s: 3 ms: 926 time passed: s: 3 ms: 976 time passed: s: 4 ms: 27 time passed: s: 4 ms: 79 time passed: s: 4 ms: 129 time passed: s: 4 ms: 182 time passed: s: 4 ms: 233 time passed: s: 4 ms: 283 time passed: s: 4 ms: 334 time passed: s: 4 ms: 384 time passed: s: 4 ms: 436 time passed: s: 4 ms: 486 time passed: s: 4 ms: 537 time passed: s: 4 ms: 587 time passed: s: 4 ms: 638 time passed: s: 4 ms: 688 time passed: s: 4 ms: 739 time passed: s: 4 ms: 789 time passed: s: 4 ms: 844 time passed: s: 4 ms: 895 time passed: s: 4 ms: 946 time passed: s: 4 ms: 997 time passed: s: 5 ms: 47 time passed: s: 5 ms: 101 time passed: s: 5 ms: 151 time passed: s: 5 ms: 202 time passed: s: 5 ms: 252 time passed: s: 5 ms: 303 time passed: s: 5 ms: 354 time passed: s: 5 ms: 404 time passed: s: 5 ms: 455
as can see(sorry perhaps long output, in case), there consistent inaccuracy present.
why so, affects , how fixed?
when process goes sleep calling sleep
function, system scheduler postpones waking until requested time spends. after may wakes process or may takes longer time.
the usleep() function cause calling thread suspended execution until either number of real-time microseconds specified argument useconds has elapsed or signal delivered calling thread , action invoke signal-catching function or terminate process. the suspension time may longer requested due scheduling of other activity system.
many oss don't guarantee wake processes right after sleep time finishes.
Comments
Post a Comment