加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 创业 > C语言 > 正文

Windows下使用Dev-C++开发基于pthread.h的多线程程序实例

发布时间:2020-12-15 03:37:42 所属栏目:C语言 来源:网络整理
导读:一、下载Windows版本的pthread 目前最新版本是: pthreads-w32-2-9-1-release.zip。 二、解压pthread到指定目录 我选择的目录是:E:DEV-CPPPthread 完成后,该目录会多出三个文件夹:Pre-built.2,pthreads.2,QueueUserAPCEx。 三、配置Dev-C++编译选项 1

一、下载Windows版本的pthread

目前最新版本是:pthreads-w32-2-9-1-release.zip。

二、解压pthread到指定目录

我选择的目录是:E:DEV-CPPPthread

完成后,该目录会多出三个文件夹:Pre-built.2,pthreads.2,QueueUserAPCEx。

三、配置Dev-C++编译选项

1)点击“工具”→“编译选项”→“目录”→“c++包含文件”,浏览到刚才解压的pthread目录,选择E:DEV-CPPPthreadPre-built.2include,添加。

2)点击“工具”→“编译选项”→“目录”→“库”,浏览到刚才解压的pthread目录,选择E:DEV-CPPPthreadPre-built.2lib,添加。

四、如果出现“undefined reference to 'pthread_create”的错误,在编译器选项中要加 -lpthread参数

五、最后附上一个简单的多线程的例子

#include <iostream> 
#include <pthread.h>  
#include<cstdio>
using namespace std; 
 
void* hjzgg(void* arg) 
{ 
  while(1){
    cout<<"Hello,everyone! I am hjzgg!"<<endl; 
    getchar();
  }
  return NULL;
} 
 
int main(int args,char* argv[]) 
{ 
  pthread_t tid; 
  pthread_create(&tid,NULL,hjzgg,NULL);   
  while(1);//主线程不要提前结束 
  return 0;  
}

以上这篇Windows下使用Dev-C++开发基于pthread.h的多线程程序实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持编程小技巧。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读