转自:https://blog.csdn.net/hsd2012/article/details/50930236
1.下载pthread 的windows安装包
可以从官方网站上下载,网址:http://sourceware.org/pthreads-win32
也可以下载我上传的资源,以下将以我上传的资源来讲解。(下载)
下载之后解压,放置在C盘
如下图:
2.配置VS2010
打开vs2010,项目->属性->配置属性->VC++目录,包含目录里添加inlude路径;在库目录那一栏添加lib路径
添加库目录的时候,根据自己的系统选择;32为选择x86;64位选择x64
在链接器—>输入,附加依赖项一栏添加 pthreadVC2.lib;pthreadVCE2.lib;pthreadVSE2.lib;如下图所示。所有设置完成后点确定
这样就设置好了,大功告成。可以创建项目测试
-
#include "stdafx.h" -
#include <iostream> -
#include <pthread.h> -
using namespace std; -
void *task1(void *X){ -
cout<<"线程A complete"<<endl; -
return (NULL); -
} -
void *task2(void *X){ -
cout<<"线程B complete"<<endl; -
return (NULL); -
} -
int main(int argc, _TCHAR* argv[]) -
{ -
pthread_t ThreadA,ThreadB; //定义线程 -
pthread_create(&ThreadA,NULL,task1,NULL); -
pthread_create(&ThreadB,NULL,task2,NULL); -
pthread_join(ThreadA,NULL); -
pthread_join(ThreadB,NULL); -
system("pause"); -
return 0; -
}
效果如下图:
--------------------- 作者:我爱默小兜 来源:CSDN 原文:https://blog.csdn.net/hsd2012/article/details/50930236?utm_source=copy 版权声明:本文为博主原创文章,转载请附上博文链接!