Windows下使用pthread
来源:互联网 发布:安装php基础环境搭建 编辑:程序博客网 时间:2024/05/17 22:33
使用pthread的好处在于对于跨平台的程序,无需重写线程部分。目前跨平台的线程库还有,Boost.Thread, Intel TBB里的线程类(与Boost.Thread接口几乎相同),ACE里的活动对象类,ICE里的线程类。
PMVS源码在多线程使用pthread,这个库一般用于linux下,要在win7 64bit下使用也挺简单:
1. 下载pthreads-w32-2-8-0-release.exe
下载地址:ftp://sourceware.org/pub/pthreads-win32
2. 安装pthreads-w32-2-8-0-release.exe
双击pthreads-w32-2-8-0-release.exe,点击Browse选择安装到的目录,然后点击Extract解压,完成后点击Done。
之后会在安装目录看到有三个文件夹Pre-built.2、pthreads.2、QueueUserAPCEx. 第一个是生成库(头文件和库文件那些),第二个是源码,第三个不清楚,像是测试程序。
将Pre-built.2文件夹下的include和lib文件夹里的文件复制到VS2008对应的include和lib目录,例如C:\Program Files(X86)\Microsoft Visual Studio 9.0\VC\include和C:\Program Files(X86)\Microsoft VisualStudio 9.0\VC\lib.
#include<stdio.h>#include<pthread.h>#include<Windows.h>#pragma comment(lib, "pthreadVC2.lib") //必须加上这句void*Function_t(void* Param){ pthread_t myid = pthread_self(); while(1) { printf("线程ID=%d \n", myid); Sleep(4000); } return NULL;}int main(){ pthread_t pid; pthread_create(&pid, NULL, Function_t,NULL); while (1) { printf("in fatherprocess!\n"); Sleep(2000); } getchar(); return 1;}
运行过程中出现缺少“pthreadVC2.dll”,这时候需要将.lib中对应的文件拷贝到windows的系统文件夹下,对于64bit,拷贝位置为“C:\Windows\SysWOW64”
0 0
- Windows下使用pthread
- Windows下使用pthread
- windows 下使用 pthread
- Windows下使用pthread
- Windows下使用pthread
- windows 下使用pthread
- Windows下使用pthread
- Windows下使用pthread
- Windows下使用pthread
- windows下使用pthread
- Windows下使用pthread
- Windows下使用pthread
- windows下使用pthread库
- windows下使用pthread库
- windows下使用pthread库
- Windows+VS2008 下使用pthread
- WINDOWS下使用PTHREAD库
- windows下使用pthread库
- MDX按层次查询
- 刷leetcode:Sqrt(x)
- eclipse生成Java注释文档
- 插入排序+冒泡排序+选择排序
- 归并排序 java语言
- Windows下使用pthread
- Linux/windows android adt自带eclipse无法设置ndk路径 jdk sdk ndk等环境配置
- Maven 构建 Struts2 实现 基本 CURD Controller
- Insertion Sort List
- Coursera Machine Learning 学习笔记(十)
- 第二周 项目四-图书馆的书
- JAVA基础(1):封装
- 互联网我来了 -- 1. Node.js 来打个招呼
- oc_study18--内存管理