c++ - 代码块 C++ 线程错误

标签 c++ multithreading codeblocks

<分区>

我有一个问题,包括线程库。以下代码:

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

using namespace std;

//The function we want to make the thread run.
void task1(string msg)
{
    cout << "task1 says: " << msg;
}

int main()
{
    // Constructs the new thread and runs it. Does not block execution.
    thread t1(task1, "Hello");

    //Makes the main thread wait for the new thread to finish execution, therefore blocks its own execution.
    t1.join();
}

产生这些错误:

enter image description here

代码取自另一个stackoverflow问题的答案。我对代码块和 C++ 还很陌生,所以请向我解释我做错了什么。

最佳答案

您可能没有为编译器设置正确的标志(因此它使用 c++11)。 Way of doing it in codeblocks

关于c++ - 代码块 C++ 线程错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30986978/

相关文章:

c++ - 静态值继承

c++ - 如何在不使用mutex、semorphore、spinLock、futex的情况下实现线程同步?

c - 我需要在 C 中实现 Butterworth 滤波器。获取具有此功能的库或编写代码是否更容易?

c++ bulid消息显示引用参数,而我按值传递参数

c++ - 从 C++ 中的时区名称获取时区偏移量

相当于 ntohll 函数的 Java

c++ - 为什么 'this' 关键字不是 C++ 中的引用类型

c++ - 使用C++11的线程基类

c++ - 从主线程向工作线程发出信号的问题

c++ - 代码块 "Other Linker Options"翻译 "Link Libraries"和库包含效率