https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80538
Bug ID: 80538 Summary: Probably unwanted thread yield for thread::sleep_for with < 1s Product: gcc Version: 7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: zulliger at indel dot ch Target Milestone: --- libstdc++-v3 configured to NOT have _GLIBCXX_USE_NANOSLEEP, but to HAVE _GLIBCXX_HAVE_SLEEP and _GLIBCXX_HAVE_USLEEP defined, causes the execution of the following code: ::sleep(__s.count()); if (__ns.count() > 0) { long __us = __ns.count() / 1000; if (__us == 0) __us = 1; ::usleep(__us); } Which means that for values of __s.count() == 0, the current thread will always "yield" (according to my understanding, sleep(0) yields), just before the thread may actually fall asleep for some microseconds. Is this really the desired behaviour? Anyway, what's the desired effect of a thread::sleep_for(0.0)? should the thread yield then? If not, then the code should look like this: if (__s.count() > 0) ::sleep(__s.count()); if (__ns.count() > 0) { long __us = __ns.count() / 1000; if (__us == 0) __us = 1; ::usleep(__us); } shouldn't it?