windows下使用pthread

windows下使用pthread坑太多。ps:pc环境windows10,x64。

以下是在该环境下的配置和编程的注意事项:

1、把pthread的文件解压缩后,把Pre-built.2文件夹中的include和lib中的文件分别复制到VS安装目录…Microsoft Visual Studio 10.0VC下的include和lib中。

 

2、#include <pthread.h>

#pragma comment(lib, "pthreadVC2.lib")

3、64位系统:在VS工程属性->配置属性->链接器->输入->附加依赖项中添加“pthreads-w32-2-9-1-releasePre-built.2libx86pthreadVC2.lib”。

4、64位系统:

应将pthreads-w32-2-9-1-releasePre-built.2dllx86 pthreadVC2.dll复制到C:WindowsSysWOW64中.。

5、创建线程:pthread_create(&sendCanMsgThread, NULL, SimulateSendCanMsg, NULL),同时创建多个线程,线程执行很快,需要延长执行时间才看得到交互执行。

 

6、等待线程结束:pthread_join(sendCanMsgThread, NULL);

原文地址:https://www.cnblogs.com/hejing-swust/p/10078000.html