跨平台的并行库 OpenMP, pthread(POsix),BOOST,thread,Intel TBB 等并行库

http://xiaoxia.org/2011/11/23/multi-threading-programing-openmp-computing-first-lession/    (写得非常好

http://hi.baidu.com/ak_ak47/item/b7ddbf358fa71ef6a8842803   (vs2008中的初始配置)

http://blog.csdn.net/wyjkk/article/details/6612108

http://blog.csdn.net/donhao/article/details/5651852  (写得非常好)

 

一些网址介绍pthread的

http://xiaoxia.org/2011/11/23/multi-threading-programing-openmp-computing-first-lession/   (很好)

http://leven.co/blog/view/19

http://www.metsky.com/archives/550.html

http://blog.csdn.net/sunboy_2050/article/details/5921003
http://my.oschina.net/michaelyuanyuan/blog/71500

win7 64bit + VS2008 下使用pthread

使用pthread的好处在于对于跨平台的程序,无需重写线程部分。目前跨平台的线程库还有,Boost.Thread, Intel TBB里的线程类(与Boost.Thread接口几乎相同),ACE里的活动对象类,ICE里的线程类。

PMVS源码在多线程使用pthread,这个库一般用于linux下,要在win7 64bit下使用也挺简单:

 

1. 下载pthreads-w32-2-8-0-release.exe

下载地址:ftp://sourceware.org/pub/pthreads-win32

 

2. 安装pthreads-w32-2-8-0-release.exe

双击pthreads-w32-2-8-0-release.exe,点击Browse选择安装到的目录,然后点击Extract解压,完成后点击Done。

之后会在安装目录看到有三个文件夹Pre-built.2、pthreads.2、QueueUserAPCEx. 第一个是生成库(头文件和库文件那些),第二个是源码,第三个不清楚,像是测试程序。

将Pre-built.2文件夹下的include和lib文件夹里的文件复制到VS2008对应的include和lib目录,例如C:\Program Files(X86)\Microsoft Visual Studio 9.0\VC\include和C:\Program Files(X86)\Microsoft VisualStudio 9.0\VC\lib.

 

3. 编写测试程序

复制代码
#include<stdio.h>
#include<pthread.h>
#include<Windows.h>
#pragma comment(lib, "pthreadVC2.lib")  //必须加上这句

void*Function_t(void* Param)
{
    pthread_t myid = pthread_self();
    while(1)
    {
        printf("线程ID=%d \n", myid);
        Sleep(4000);
    }
    return NULL;
}

int main()
{
    pthread_t pid;
    pthread_create(&pid, NULL, Function_t,NULL);
    while (1)
    {
        printf("in fatherprocess!\n");
        Sleep(2000);
    }
    getchar();
    return 1;
}
复制代码

运行过程中出现缺少“pthreadVC2.dll”,这时候需要将.lib中对应的文件拷贝到windows的系统文件夹下,对于64bit,拷贝位置为“C:\Windows\SysWOW64”

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值