简体   繁体   English

VSCode C ++-#include <thread>

[英]VSCode C++ - #include <thread>

I'm using Visual Studio Code with C++ extension and g++ as my compiler. 我使用带有C ++扩展名和g ++的Visual Studio Code作为我的编译器。 I'm trying to get my environment configured for threading but not having much luck. 我正在尝试为线程配置我的环境,但运气不佳。 I tried installing POSIX threading via MinGW Installer but I'm not really sure how to include it properly in my project or include paths. 我尝试通过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();
}

In this case #include does not an error but std::thread is undefined. 在这种情况下,#include不会出错,但是std :: thread是未定义的。

c_cpp_properties.json: 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"
}

Turns out thread isn't really supported... 原来并不真正支持线程...

#include <thread>

But POSIX threads are so I ended up using them instead: 但是POSIX线程是这样,所以我最终改为使用它们:

#include <pthread.h>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM