c++ 多线程

mac2022-06-30  99

1.多线程初次使用:

// thread example #include <iostream> #include <thread> using namespace std; void foo() { //do stuff } void bar(int x) { //do stuff } int main() { thread first (foo); //spawn new thread that calls foo() thread second (bar, 0); //spawn new thread that calls bar(0) cout << "main, foo and bar now execute concurrently...\n"; first.join(); second.join(); cout << "foo and bar completed.\n"; return 0; }

2.关于g++编译时候需要注意,不同g++版本可能不一样。

g++  thread.cpp -o thread -lpthread -std=c++11

转载于:https://www.cnblogs.com/Shinered/p/9061824.html

相关资源:c语言多线程操作
最新回复(0)