FS#37816 - [gcc] G++ std::this_thread::yield is a no-op (and other issues)

Attached to Project: Arch Linux
Opened by nightstrike (nightstrike) - Monday, 18 November 2013, 04:28 GMT
Last edited by Allan McRae (Allan) - Wednesday, 20 November 2013, 02:54 GMT
Task Type Bug Report
Category Packages: Core
Status Closed
Assigned To Allan McRae (Allan)
Architecture All
Severity Medium
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Description:
GCC is not configured with --enable-libstdcxx-time. Therefore, yield() winds up being a no-op, instead of a call out to sched_yield(). In 4.9, this option should no longer be needed, but for 4.8 it is. If the option is added, it should be removed for 4.9. But please, build a 4.8 with this option in use so that I don't have to manually edit c++config.h.

See: http://stackoverflow.com/a/12961816
Longer link: http://stackoverflow.com/questions/12523122/what-is-glibcxx-use-nanosleep-all-about

Note that the particular configure option has several side effects, only one of which is the broken yield().

Additional info:
* 4.7, 4.8 only
This task depends upon

Closed by  Allan McRae (Allan)
Wednesday, 20 November 2013, 02:54 GMT
Reason for closing:  Won't implement
Comment by Allan McRae (Allan) - Monday, 18 November 2013, 06:55 GMT
Building with that configure option was an ABI breaker, so it will not be done. Not that it is needed anyway...

So what are you editing? In c++/4.8.2/x86_64-unknown-linux-gnu/bits/c++config.h I have (as expected in gcc-4.8.1+)

#define _GLIBCXX_USE_CLOCK_REALTIME 1
Comment by nightstrike (nightstrike) - Monday, 18 November 2013, 17:13 GMT
I'm not sure what the USE_CLOCK_REALTIME macro that you mentioned has to do with anything. The bug report and the stack overflow posts all boil down to the macros _GLIBCXX_USE_NANOSLEEP and _GLIBCXX_USE_SCHED_YIELD, which are both undefined in the archlinux version of 4.8.2 c++config.h.

The latter makes std::this_thread::yield() turn into this:

/// yield
inline void
yield() noexcept
{
#ifdef _GLIBCXX_USE_SCHED_YIELD
__gthread_yield();
#endif
}

simplifying....
void yield() { }

So a yielding process never actually yields. Which means code compiled using your compiler can't use the yield from the C++ standard library, instead having to call out to the linux-specific sched_yield, which also requires pulling in all of sched.h into the global namespace -- hardly a good situation for anyone.
Comment by Allan McRae (Allan) - Wednesday, 20 November 2013, 02:54 GMT
Ah - the clock realtime thing used to be enabled with --enable-libstdcxx-time but got added by default in 4.8.1. I thought the other effects of that configure option were enabled too but seems that was only for 4.9.0

However, I am not enabling this configure due to it being a potential ABI breaker.

Loading...