当前位置: 代码迷 >> 综合 >> Enable multithreading to use std::thread: Operation not permitted
  详细解决方案

Enable multithreading to use std::thread: Operation not permitted

热度:39   发布时间:2023-12-13 06:10:38.0

简单示例

#include <iostream>
#include <thread>void hello() {
    std::cout << "hello world" << std::endl;
}int main() {
    std::thread t(hello);t.join();
}

编译命令:

g++ -std=c++11 hello.cpp -o hello -pthread

C++支持多线程,有三点注意:

  1. 包含头文件#include <thread>
  2. 编译选项-std=c++11
  3. 编译选项-pthread

不添加编译选项-pthread,则运行出现Enable multithreading to use std::thread: Operation not permitted

选项中指定-lpthread-pthread一样,建议使用-pthread

  相关解决方案