On Monday, 30 September 2019 08:05:23 PDT Ola Røer Thorsen wrote: > man. 30. sep. 2019 kl. 16:48 skrev Thiago Macieira < > > thiago.macie...@intel.com>: > > It's just wrong to use it. Just like QThread::{,m,u}sleep. Don't use them. > > What's wrong with the sleep functions in particular? Are they worse than > calling for example unistd.h's "usleep" or > "std::this_thread::sleep_for(std::chrono::milliseconds(x));"?
The problem with the sleep functions is that they sleep for an amount of time different than the actual amount of time that you needed to sleep for. Note: *needed* to sleep for, not *coded* for. Pretty much any time span different from 0 is wrong in at least one circumstance: either you're sleeping too little, in which case you woke the system up early and are consuming CPU time and battery, or you slept too much and you delayed processing some incoming event. Usually, it's both: you wake up early, consume battery, handle no events, then go back to sleep. Then the event you needed to handle arrives while you're still sleeping. Don't sleep with a timeout. Sleep until *exactly* your event arrives, no sooner and no later. -- Thiago Macieira - thiago.macieira (AT) intel.com Software Architect - Intel System Software Products _______________________________________________ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest