- 下载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 配置
猜你喜欢
转载自blog.csdn.net/fwb330198372/article/details/85626222
今日推荐
周排行