C/C++多线程编程之一】VC6.0安装pthread

多线程编程VC6.0安装pthread

     多线程是C/C++的一个重要的概念,在windows下,需要安装pthread来支持多线程编程。以下配置本人亲测成功,另外此次配置实际上与编译器无关,故其他编译器如VS2010等可参照本人配置。

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

 

 

       

2.解压pthreads-w32-2-8-0-release.zip

           解压后如下:

         

 

3.运行pthreads-w32-2-8-0-release.exe

扫描二维码关注公众号,回复: 2449254 查看本文章

          弹出的对话框点击:Extract,结束后点击Done完成。运行后如下:

           

 

          我们需要的文件夹是Pre-built.2,另外两个文件夹不需要。

3.拷贝include内文件

          点开Pre-built.2文件夹:

         

 

          将include内的3个文件(如下):

         

 

          将这3个文件复制到VC6.0对应的include文件夹内:我的路径是:E:\Mysoftware\VC98\Include

4.拷贝bin内文件

          点开include下面的lib文件夹(含10个文件如下):

          

 

           将这10个文件复制到VC6.0对应的bin文件夹内:我的路径是:E:\Mysoftware\VC98\Bin

5.将pthreadVC2.dll添加到系统

          如果用Win8,将上面bin文件中的pthreadVC2.dll复制到:C:\Windows\System 

          

 

 

          其他Windows操作系统,则复制到:C:\Windows\System32(注Win8最好也复制一个到这个文件夹,可以提供32位程序支持)。

6.测试程序

     

 

      

 

#include "pthread.h"

#include "sched.h"

#include "semaphore.h"

#include "stdio.h"

 

#pragma comment(lib, "pthreadVC2.lib")  //必须加上这句

 

void* tprocess1(void* args)

{

int i = 1;

while(i <= 100)

{

printf("process1:%d\n", i);

i++;

}

return NULL;

}

 

void* tprocess2(void* args)

{

int i = 1;

while(i <= 100)

{

printf("process2:%d\n", i);

i++;

 

}

return NULL;

}

 

int main()

{

pthread_t        t1;

pthread_t        t2;

 

pthread_create(&t1,NULL,tprocess1,NULL);

pthread_create(&t2,NULL,tprocess2,NULL);

 

pthread_join(t1,NULL);

pthread_join(t2,NULL);

 

return 0;

}

 

 

          读者只需运行一下这个测试程序即可,以后会学习关于Pthread的更多知识。

          

          这便是线程1和线程2交替运行的结果啦!NICE!

          再次提醒一下哦,此次配置与编译器无关,其他编译器也可参照配置哦。开始多线程编程之旅吧!

 

来自 <https://blog.csdn.net/lovecodeless/article/details/22751299>

猜你喜欢

转载自blog.csdn.net/zcc1229936385/article/details/81230926
今日推荐