国产探花免费观看_亚洲丰满少妇自慰呻吟_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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 永昌县| 乌拉特中旗| 五河县| 高青县| 梅州市| 珠海市| 河间市| 岫岩| 扶余县| 辽宁省| 墨脱县| 特克斯县| 恭城| 噶尔县| 四川省| 宜昌市| 龙门县| 安新县| 赫章县| 四会市| 鄂尔多斯市| 久治县| 莱西市| 城步| 北安市| 安化县| 德阳市| 措美县| 乌鲁木齐县| 安阳县| 陇南市| 外汇| 黄龙县| 科技| 南召县| 城市| 宾阳县| 满洲里市| 威远县| 贵溪市| 拜城县|