spa*_*c24 7 c++ macos multithreading std
我正在尝试使用MacOS X Mavericks中的标准C++(与XCode一起安装)中的线程运行一些代码.但是我遇到了一些错误.这是一个最小的工作示例:
#include <thread>
#include <iostream>
void run (int x) {
std::cout<<".";
}
int main (int argc, char const *argv[])
{
std::thread t(run);
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误:
minimal.cpp:10:17: error: no matching constructor for initialization of 'std::thread'
std::thread t(run,0);
^ ~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/thread:372:9: note: candidate constructor template not viable: requires single argument '__f', but 2 arguments
were provided
thread::thread(_Fp __f)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/thread:261:5: note: candidate constructor not viable: requires 1 argument, but 2 were provided
thread(const thread&);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/thread:268:5: note: candidate constructor not viable: requires 0 arguments, but 2 were provided
thread() _NOEXCEPT : __t_(0) {}
^
1 error generated.
Run Code Online (Sandbox Code Playgroud)
我已经能够跟踪问题到我的编译器定义_LIBCPP_HAS_NO_VARIADICS
,这是由于定义的
#if !(__has_feature(cxx_variadic_templates))
#define _LIBCPP_HAS_NO_VARIADICS
#endif
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.
谢谢!
spa*_*c24 21
谢谢pwny
和PeterT
,我想出了错误.
我只需要编译,clang++ -std=c++11 minimal.cpp
它就像一个魅力.最后我还需要一个t.join()
来防止执行错误的发生.
归档时间: |
|
查看次数: |
8317 次 |
最近记录: |