简体   繁体   English

'yield'不是'std :: this_thread'的成员

[英]'yield' is not a member of 'std::this_thread'

I tried to yield current thread: 我试图产生当前线程:

std::this_thread::yield(); 的std :: this_thread ::收率();

But unfortunately GCC knows better: 但不幸的是GCC知道的更好:

'yield' is not a member of 'std::this_thread' 'yield'不是'std :: this_thread'的成员

Have I forgotten about some hack similar to D_GLIBCXX_USE_NANOSLEEP, or what? 我忘了一些类似于D_GLIBCXX_USE_NANOSLEEP的黑客攻击,或者是什么?

Yes, this appears to be an issue similar to the one with _GLIBCXX_USE_NANOSLEEP . 是的,这似乎是与_GLIBCXX_USE_NANOSLEEP类似的问题。 GCC has yield conditionally compiled depending on the macro _GLIBCXX_USE_SCHED_YIELD . GCC根据宏_GLIBCXX_USE_SCHED_YIELD有条件地编译yield It should compile if you define that. 如果你定义它,它应该编译。

This will be fixed as of GCC 4.8. 这将在GCC 4.8中修复。

You shouldn't define _GLIBCXX_USE_NANOSLEEP or _GLIBCXX_USE_SCHED_YIELD in your code. 您不应在代码中定义_GLIBCXX_USE_NANOSLEEP_GLIBCXX_USE_SCHED_YIELD They are GCC/libstdc++-internal macros, so that's what should define it. 它们是GCC / libstdc ++ - 内部宏,所以应该定义它。 If they aren't defined, it's because GCC wasn't configured with the option to check for availability of the functions. 如果没有定义它们,那是因为GCC没有配置检查功能可用性的选项。 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. 因为对于你正在使用的任何系统来说,启用该选项显然没有任何缺点,你可以问任何提供你的GCC的人这样做。 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. 在此之前,比在代码中启用宏更安全的hack是修改系统上的c++config.h文件以定义宏。

You may need to use '--enable-libstdcxx-time' when configuring gcc to enable detection of sched_yield. 在配置gcc以启用sched_yield检测时,您可能需要使用'--enable-libstdcxx-time'。 For some reason, there is a single check for multiple features 出于某种原因,只需检查多个功能

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 std::this_thread::yield() 对比 std::this_thread::sleep_for() - std::this_thread::yield() vs std::this_thread::sleep_for() 如何确定性地使用std :: this_thread :: yield()? - How to use std::this_thread::yield() deterministically? std :: this_thread :: yield只是一个提示会出现问题吗? - Can std::this_thread::yield being just a hint be problematic? C++11 线程等待行为:std::this_thread::yield() 与 std::this_thread::sleep_for( std::chrono::milliseconds(1) ) - C++11 Thread waiting behaviour: std::this_thread::yield() vs. std::this_thread::sleep_for( std::chrono::milliseconds(1) ) 从std :: cin进行的非阻塞读取是否与std :: this_thread :: sleep_for()或std :: this_thread :: yield()(IPC)一起使用 - Does non-blocking read from std::cin work with std::this_thread::sleep_for() or std::this_thread::yield() (IPC) C++11“native_handle”不是“std::this_thread”的成员 - C++11 'native_handle' is not a member of 'std::this_thread' std::this_thread::yield 与 Linux 上的 sched_yield 有什么不同吗? - Is std::this_thread::yield any different from sched_yield on linux? 如果延迟很重要,我应该在繁忙的循环中使用std :: this_thread :: yield吗? - Should I use std::this_thread::yield in a busy loop if the latency matters? mingw 5 std :: this_thread未定义 - mingw 5 std::this_thread not defined jthread 的 std::this_thread 在哪里? - Where is std::this_thread for jthread?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM