Windows系统下pthread环境配置

记录下win7系统,vc6.0++编译器下配置POSIX多线程环境的步骤。

配置
  1. 下载地址 ftp://sourceware.org/pub/pthreads-win32/
    我下载的版本是 fpthreads-w32-2-1-0-release.exe 2005/3/16
    运行后点Exract,解压完成后再点Done,可以看到三个文件夹,但只需要用到Pre-built.2文件夹。

  2. Pre-built.2/include中的三个头文件复制到vc的Include文件夹内

  3. Pre-built.2/lib中的8个文件复制到vc的Bin文件夹内(不知道需不需要,反正移就完事了)

  4. Pre-built.2/lib中的pthreadVC2.libpthreadVSE2.lib复制到vc的Lib文件夹里(否则会出现链接错误LNK1104:cannot open file "pthreadVC2.lib"

  5. Pre-built.2/lib中的pthreadVC2.dll文件复制到C:\Windows\system里面(我的电脑中有system和system32两个文件夹,试了下发现应该放在system中)

  6. 配置完成,编程的时候需要包含pthread.h头文件,并且要加上一句#pragma comment(lib, "pthreadVC2.lib") (否则会出现链接错误)

测试
#include <cstdio>
#include <pthread.h>
#pragma comment(lib, "pthreadVC2.lib")

void * fun(void * arg) {
    printf("Hello, %s\n", (char *) arg);

    return NULL;
}

int main(void) {
    pthread_t t1, t2;

    pthread_create(&t1, NULL, fun, "thread1");
    pthread_create(&t2, NULL, fun, "thread2");
    pthread_join(t1, NULL);
    pthread_join(t2, NULL);

    return 0;
}

输出结果

Hello, thread1
Hello, thread2
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值