[英]C++11 Threads, is it valid code?
I am playing around with threads features of C++11. 我在玩C ++ 11的线程功能。 But the following code does not compile under both clang (3.5) and gcc (4.9.2).
但是以下代码无法同时在clang(3.5)和gcc(4.9.2)下编译。
#include <iostream>
#include <thread>
void add(int& x) {
x += 1;
}
int main (int argc, char const *argv[])
{
int x{ 5 };
int y{ 8 };
std::thread my_thread_1{ add, x };
std::thread my_thread_2{ add, y };
my_thread_1.join();
my_thread_2.join();
std::cout << x << " " << y << std::endl;
return 0;
}
Is it valid C++11? 它是有效的C ++ 11吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.