- 下載pthread, 下載地址
- 項目配置(測試使用絕對路徑,最好跟據自己的項目修改成相對路徑):
- C/C++
- 常規->附加包含目錄:D:\Project\third_party\pthreads\Pre-built.2\include
- 預處理器->預處理器定義:增加 HAVE_STRUCT_TIMESPEC;
- 鏈接器(開發環境爲x64,故配置x64的,如果爲32位,需要改成x86):
- 預處理器->附加庫目錄:D:\Project\third_party\pthreads\Pre-built.2\lib\x64
- 輸入->附加依賴項:添加 pthreadVC2.lib;
- C/C++
- 測試代碼:
-
#include <iostream> #include<pthread.h> using namespace std; #define NUM_THREADS 5 void* say_hello(void* args) { cout << "hello wolrd!" << endl; return 0; } int main() { pthread_t tids[NUM_THREADS]; for (int i = 0; i < NUM_THREADS; ++i) { int ret = pthread_create(&tids[i], NULL, say_hello, NULL); if (ret != 0) { cout << "pthread_create error_code=" << ret << endl; } } pthread_exit(NULL); return 0; }
-
windows pthread 配置
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.