65,186
社区成员




// ConsoleApplication2.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <thread>
#include "iostream"
using namespace std;
thread_local int g_n = 1;
void f()
{
g_n++;
printf("id=%d, n=%d\n", std::this_thread::get_id(), g_n);
}
void foo()
{
thread_local int i = 0;
printf("id=%d, n=%d\n", std::this_thread::get_id(), i);
i++;
}
void f2()
{
foo();
foo();
}
int _tmain(int argc, _TCHAR* argv[])
{
g_n++;
f();
std::thread t1(f);
std::thread t2(f);
t1.join();
t2.join();
f2();
std::thread t4(f2);
std::thread t5(f2);
t4.join();
t5.join();
return 0;
}
1>------ 已启动生成: 项目: ConsoleApplication2, 配置: Debug Win32 ------
1> ConsoleApplication2.cpp
1>c:\users\hjg\documents\visual studio 2013\projects\consoleapplication2\consoleapplication2.cpp(9): error C2144: 语法错误:“int”的前面应有“;”
1>c:\users\hjg\documents\visual studio 2013\projects\consoleapplication2\consoleapplication2.cpp(9): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\users\hjg\documents\visual studio 2013\projects\consoleapplication2\consoleapplication2.cpp(19): error C2144: 语法错误:“int”的前面应有“;”
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========