mingw using pthread
转载http://www.cnblogs.com/tfanalysis/p/5505163.html
ftp://sourceware.org/pub/pthreads-win32/
有的时候需要使用多线程来测试代码啥的,在Linux下有pthread,在windows也有。
我这儿是使用MingW作为编译工具,具体如何下载MingW自行在网上搜索。
而pthread是在这里下载的:ftp://sourceware.org/pub/pthreads-win32/pthreads-w32-2-9-1-release.zip
将下载来的包解压,然后将Pre-built.2中的include下的文件拷贝到mingw/include中,将lib/x86(或x64)/libpthreadGC2.a拷贝到mingw/lib中。
之后使用的时候,在Eclipse的Linker选项里添加一个新的库pthreadGC2即可了。
下面是源代码:

- /*
- ============================================================================
- Name : t3.c
- Author : Merlin
- Version :
- Copyright : Your copyright notice
- Description : Hello World in C, Ansi-style
- ============================================================================
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <pthread.h>
- #include <windows.h>
- void *thread1(void *arg)
- {
- while (1)
- {
- printf("T1T1T1T1T1T1T1T1T1T1T1\n");
- fflush(stdout);
- Sleep(1000);
- }
- return NULL;
- }
- void *thread2(void *arg)
- {
- while (1)
- {
- printf("T2T2T2T2T2\n");
- fflush(stdout);
- Sleep(2000);
- }
- return NULL;
- }
- int main(void)
- {
- void *Tret;
- pthread_t Tid1, Tid2;
- // HWND Wnd;
- // Wnd = FindWindow(NULL, "微信");
- // if (Wnd)
- // {
- //// SendMessage(Wnd, WM_CLOSE, 0, 0);
- // ShowWindow(Wnd, SW_HIDE);
- // Sleep(2000);
- // ShowWindow(Wnd, SW_SHOW);
- // Sleep(2000);
- // ShowWindow(Wnd, SW_HIDE);
- // }
- printf("Hello, this is a example test pthread.\n");
- pthread_create(&Tid1, NULL, thread1, NULL);
- pthread_create(&Tid2, NULL, thread2, NULL);
- pthread_join(Tid2, &Tret);
- Sleep(100);
- printf("End, this is a example test pthread.\n");
- return EXIT_SUCCESS;
- }

需要着重说明的函数是pthread_join,功能是等待Tid2线程返回才会继续向下跑。
执行结果:
报错误1:e:\mingw\include\pthread.h:320:8: error: redefinition of 'struct timespec'
那么在GCC C Compiler -> Symbols中添加HAVE_STRUCT_TIMESPEC定义。
如上面的方法不行,那么使用mingw-install-setup.exe添加安装pthread相关的库:
mingw using pthread的更多相关文章
- CodeBlocks配置pthread环境
参考资料:MinGW配置pthread环境 按[参考资料]里说的[下载资源]后,将libpthreadGC2.a放到codeBlocks安装目录下的MinGW\lib目录下,然后将pthread.h ...
- windows下使用pthread
有的时候需要使用多线程来测试代码啥的,在Linux下有pthread,在windows也有. 我这儿是使用MingW作为编译工具,具体如何下载MingW自行在网上搜索. 而pthread是在这里下载的 ...
- Windows下安装MinGW,编译c/c++时出现cannot find -lpthread解决办法
由于Mingw下没有带pthread库,所以在eclipse中设置多线程动态链接库,也不管用.需要自己下载, ftp://sourceware.org/pub/pthreads-win32/pthre ...
- 在Windows下利用MinGW编译FFmpeg
目录 [隐藏] 1 环境与软件 2 第一步:安装MinGW 3 第二步:配置编译环境 4 第三步:配置SDL 5 第四步:编译 5.1 编译faac 5.2 编译fdk-aac 5.3 编译x264 ...
- HOWTO Install the MinGW (GCC) Compiler Suite
Posted July 25th, 2008 by mingwadmin getting started install mingw Automated Installer If you are ne ...
- eclipse mingw cpp开发环境
Eclipse开发c++ 对比:微软的VC++6.0:太老了,对win7兼容不好, 现在微软的Visual Studio:安装包太大,好几个G,装了一堆你不需要的东西,要钱,教 育版申请麻烦 DOS下 ...
- [科普]MinGW vs MinGW-W64及其它
转载:http://tieba.baidu.com/p/3186234212?pid=54372018139&cid=#54372018139 这里也转一下吧. 部分参照备忘录原文: bitb ...
- MinGW 使用 msvcr90.dll
MinGW 编译出来的程序总是使用 VC6 的 msvcrt.dll ,VC8,9,10有很多新的API(仅限于c runtime),想使用怎么办? 比如:boost 对 MinGW 最低要求就是 m ...
- linux下使用mingw编译NSIS-3.03
简述 最近在研究使用NSIS做安装包,语法不算复杂,插件也很多,中文资料也不少,还挺好用的.先后用NSIS做出了安装和卸载需要输入密码,通过自定义页面实现安装时候选择多个目录.安装的时候输入配置文件信 ...
随机推荐
- 浅谈StringBuffer
StringBuffer,由名字可以看出,是一个String的缓冲区,也就是说一个类似于String的字符串缓冲区,和String不同的是,它可以被修改,而且是线程安全的.StringBuffer在任 ...
- leecode第二百一十五题(数组中的第K个最大元素)
class Solution { public: int quick_sort_version(vector<int>& nums, int k,int begin,int end ...
- 使用echarts时option可以复用的方法
其实复用option很简单,在所要展示的图形在其他需求大致一致时,即可写一个option然后设置不同的地方就好了,坐标轴.series等都可以设置,具体代码如下: var barLeft = echa ...
- box-sizing 和 dom width
refer : https://developer.mozilla.org/en-US/docs/Web/API/CSS_Object_Model/Determining_the_dimensions ...
- Jellyfish详解
一.Jellyfish简介 JELLYFISH是CBCB(Center for Bioinformatics and Computational Biology)的Guillaume Marçais ...
- Openstack中查看虚拟机console log的几种方法
Openstack中有时候虚拟机启动不正常,这时可以通过查看虚拟机console log能得到一些有用的信息. 有这些方法可以查看或获取虚拟机console log: 1)openstack控制台图形 ...
- 【洛谷p1605】迷宫
(还记得我昨天大概没人看到的博客(我删辽)吗qwq,2019.4.14下午交的qwq 那篇博客大致内容就是:我提交楼上这道题,交了好久好久好久好久 现在我告诉你,那次评测还N/A着呢qwq) tqlq ...
- .net正则IP加端口,并返回IP加端口
public string GetIp(string url) { var reg = new Regex(@"\d{2,3}([.]\d{1,3}){3}:\d{2,5}"); ...
- 纪念L.A. Zadeh教授
扎德教授永远活在我们心中 汪 培 庄 辽宁工程技术大学,智能工程与数学研究院,阜新,123000 摘要 全球科技工作者都在悼念扎德教授的逝世.本文对扎德创立模糊数学的历史意义,他与中国同仁的关系和影响 ...
- 用python写一个定时提醒程序
身体是革命的本钱,身体健康了我们才有更多精力做自己想做的事情,追求女神,追求梦想.然而程序员是一个苦比的职业,大部分时间都对着电脑,我现在颈椎就不好了,有时候眼睛还疼,我还没20阿,伤心...于是乎写 ...