国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C++ > 正文

c++之std::thread多線程的使用和獲取pid/tid

2019-11-08 03:24:41
字體:
來源:轉載
供稿:網友
// thread example#include <iostream>       // std::cout#include <thread>         // std::thread#ifdef _WIN32#include <PRocess.h>#define getpid _getpid#else#include <unistd.h>#endifvoid foo(){	// do stuff...	int pid = getpid();	std::cout << "pid=" <<pid<<",tid=" << std::this_thread::get_id() << ",first thread foo/n";		}void bar(int x){	// do stuff...	int pid = getpid();	std::cout << "pid=" << pid << ",tid=" << std::this_thread::get_id() << ",second thread bar/n";}//c++之std::thread多線程的使用和獲取pid/tidint main(){	std::thread first(foo);     // spawn new thread that calls foo()	std::thread second(bar, 0);  // spawn new thread that calls bar(0)	int pid = getpid();	std::cout << "pid=" << pid<<",tid=" << std::this_thread::get_id()<<",main, foo and bar now execute concurrently.../n";	// synchronize threads:	first.join();                // pauses until first finishes	second.join();               // pauses until second finishes	std::cout << "foo and bar completed./n";	system("pause");	return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 林西县| 英吉沙县| 渭源县| 和硕县| 盖州市| 石林| 兰西县| 张北县| 怀化市| 武隆县| 丹江口市| 临武县| 辽阳市| 建水县| 轮台县| 青岛市| 黄大仙区| 佛坪县| 张家口市| 沐川县| 阳城县| 固始县| 东辽县| 从化市| 周至县| 呼和浩特市| 阳新县| 宜宾县| 仙居县| 金山区| 高唐县| 岱山县| 仪征市| 阜城县| 弥勒县| 双牌县| 昌乐县| 利川市| 封开县| 冷水江市| 株洲县|