Windows下使用Dev-C++开发基于pthread.h的多线程程序
生活随笔
收集整理的這篇文章主要介紹了
Windows下使用Dev-C++开发基于pthread.h的多线程程序
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、下載Windows版本的pthread
????目前最新版本是:pthreads-w32-2-9-1-release.zip。
?
二、解壓pthread到指定目錄
我選擇的目錄是:E:\DEV-CPP\Pthread 完成后,該目錄會多出三個文件夾:Pre-built.2,pthreads.2,QueueUserAPCEx。 三、配置Dev-C++編譯選項????1)點擊“工具”→“編譯選項”→“目錄”→“c++包含文件”,瀏覽到剛才解壓的pthread目錄,選擇E:\DEV-CPP\Pthread\Pre-built.2\include,添加。?
????2)點擊“工具”→“編譯選項”→“目錄”→“庫”,瀏覽到剛才解壓的pthread目錄,選擇E:\DEV-CPP\Pthread\Pre-built.2\lib,添加。
? 四、如果出現“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; }
?
本文轉自 小眼兒 博客園博客,原文鏈接:http://www.cnblogs.com/hujunzheng/p/4815033.html,如需轉載請自行聯系原作者
總結
以上是生活随笔為你收集整理的Windows下使用Dev-C++开发基于pthread.h的多线程程序的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一个用了统计CPU 内存 硬盘 使用率的
- 下一篇: MYSQL韩文显示正常一法