9

I tried to yield current thread:

std::this_thread::yield();

But unfortunately GCC knows better:

'yield' is not a member of 'std::this_thread'

Have I forgotten about some hack similar to D_GLIBCXX_USE_NANOSLEEP, or what?

Mankarse
  • 39,818
  • 11
  • 97
  • 141
Dejwi
  • 4,393
  • 12
  • 45
  • 74

3 Answers3

13

Yes, this appears to be an issue similar to the one with _GLIBCXX_USE_NANOSLEEP. GCC has yield conditionally compiled depending on the macro _GLIBCXX_USE_SCHED_YIELD. It should compile if you define that.

This will be fixed as of GCC 4.8.

Stephan Dollberg
  • 32,985
  • 16
  • 81
  • 107
R. Martinho Fernandes
  • 228,013
  • 71
  • 433
  • 510
7

You shouldn't define _GLIBCXX_USE_NANOSLEEP or _GLIBCXX_USE_SCHED_YIELD in your code. They are GCC/libstdc++-internal macros, so that's what should define it. If they aren't defined, it's because GCC wasn't configured with the option to check for availability of the functions. Since there are apparently no downsides to enabling that option for whatever system it is you're using, you could ask whoever provides your GCC to do so. Until that's done, a safer hack than enabling the macro in your code is to modify the c++config.h file on your system to define the macros.

1

You may need to use '--enable-libstdcxx-time' when configuring gcc to enable detection of sched_yield. For some reason, there is a single check for multiple features