VSCode C ++ - #include <thread>

时间:2018-04-14 17:41:33

标签: c++ multithreading visual-studio-code

我使用带有C ++扩展的Visual Studio代码和g ++作为我的编译器。我试图让我的环境配置为线程但没有太多运气。我尝试通过MinGW Installer安装POSIX线程,但我不确定如何在我的项目中正确包含它或包含路径。

#include <string>
#include <iostream>
#include <thread>

void task1(string msg){
    cout << "task1 says: " << msg;
}

int main(){
    std::thread t1(task1, "Hello");
    t1.join();
}

在这种情况下,#include不会出错,但std :: thread未定义。

c_cpp_properties.json:

{
    "name": "Win32",
    "intelliSenseMode": "clang-x64",
    "includePath": [
        "${workspaceRoot}",
        "C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++",
        "C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++/mingw32",
        "C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++/backward",
        "C:/MinGW/lib/gcc/mingw32/6.3.0/include",
        "C:/MinGW/include",
        "C:/MinGW/lib/gcc/mingw32/6.3.0/include-fixed"
    ],
    "defines": [
        "_DEBUG",
        "UNICODE",
        "__GNUC__=6",
        "__cdecl=__attribute__((__cdecl__))",
        "__SIZE_TYPE__=long long unsigned int"
    ],
    "browse": {
        "path": [
            "C:/MinGW/lib/gcc/mingw32/6.3.0/include",
            "C:/MinGW/lib/gcc/mingw32/6.3.0/include-fixed",
            "C:/MinGW/include/*"
        ],
        "limitSymbolsToIncludedHeaders": true,
        "databaseFilename": ""
    },
    "cStandard": "c11",
    "cppStandard": "c++17"
}

1 个答案:

答案 0 :(得分:0)

结果证明线程并非真正支持......

#include <thread>

但POSIX线程是这样我最终使用它们了:

#include <pthread.h>