Windows下pthread多线程使用(1):准备工作
来源:互联网 发布:php网盘源码 编辑:程序博客网 时间:2024/06/04 06:41
下载pthreads-win32: http://sourceware.org/pthreads-win32/ 目前最新的似乎是2.9.1版本
根据你目标平台,选择并设置pthread的include、lib、dll(或bin)目录(请添加到path变量)
编写可用于windows的unistd.h (这里将此文件保存为unistd_windows.h)
#ifndef _UNISTD_H#define _UNISTD_H 1/* This file intended to serve as a drop-in replacement for* unistd.h on Windows* Please add functionality as neeeded*/#include<stdlib.h>#include<io.h>#include <process.h>#define srandom srand#define random randconst int W_OK = 2;const int R_OK = 4;#define access _access#define ftruncate _chsize#define ssize_t int#define STDIN_FILENO 0#define STDOUT_FILENO 1#define STDERR_FILENO 2/* should be in some equivalent to <sys/types.h> */typedef __int8 int8_t;typedef __int16 int16_t;typedef __int32 int32_t;typedef __int64 int64_t;typedef unsigned __int8 uint8_t;typedef unsigned __int16 uint16_t;typedef unsigned __int32 uint32_t;typedef unsigned __int64 uint64_t;#endif /* unistd.h */
你的头文件可能会是如下这样子(保存为cmnheader.h)
#define _MULTI_THREADED #include <pthread.h> #include <stdio.h>#include <string.h>#include <stdlib.h> #include <unistd_windows.h> #include <windows.h>#pragma comment(lib,"pthreadVC2.lib")#define __VOID(p) ((void*)(p))#define __INT(p) ((int)(p))#define checkResults(string, value) \{ \if (value!= 0) \{ \printf("Failed with %d at %s", value, string); \exit(1); \} \}
接下来就可以开始使用了
0 0
- Windows下pthread多线程使用(1):准备工作
- Windows下pthread多线程使用(2):CreateThread
- Windows下pthread多线程使用(3):ExitThread
- Windows下pthread多线程使用(4):CancelThread
- Windows下pthread多线程使用(5):WaitForAnEnd
- 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库
- 虚拟机的理解
- php自动获取字符串编码函数mb_detect_encoding
- 如何做到每天写代码?
- 输入控制 轴旋转
- 2014-04-17工作日志:关于注册表的几个函数,我的总结。。。
- Windows下pthread多线程使用(1):准备工作
- C/C++基本数据结构:有序二叉树的基本概念和实现
- 2万字库PHP汉字转拼音(UTF-8)
- 各大“宝宝”抢滩定期理财
- wait_event_interruptible()和wait_up_interruptible()
- C++中继承与动态内存分配
- 删除系统共享
- 正则表达式
- 坎坤小K WiFi智能插座 世界上最小 拆解评测