zoukankan      html  css  js  c++  java
  • Windows下使用Dev-C++开发基于pthread.h的多线程程序

    一、下载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,添加。 
    Windows下使用Dev-C++开发基于pthread.h的多线程程序 - Einstein - 似水流年

        2)点击“工具”→“编译选项”→“目录”→“库”,浏览到刚才解压的pthread目录,选择E:DEV-CPPPthreadPre-built.2lib,添加。
    Windows下使用Dev-C++开发基于pthread.h的多线程程序 - Einstein - 似水流年 
     
    四、如果出现“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;    
    } 
  • 相关阅读:
    04_Javascript初步第二天(上)
    用python实现省市县多级嵌套下拉列表
    爬虫之 BeautifulSoup与Xpath
    爬虫之 selenium模块
    爬虫请求库 requests
    抽屉网自动点赞 评论
    爬取京东商品信息
    爬取豆瓣电影top250
    爬虫基本原理
    Django auth认证
  • 原文地址:https://www.cnblogs.com/hujunzheng/p/4815033.html
Copyright © 2011-2022 走看看