找不到pthread.h
1.Pthread是由POSIX提出的一套通用的线程库,在Linux平台下,它被广泛的支持,而windows平台下,却并不被支持,可以下载pthreads-w32替换!
2.如果不考虑下载第三方库替换,可以用window自带线程接口
(1)宏定义区分两个系统不同头文件
#if defined(_WINDOWS)
#include <windows.h>
#include <process.h>
#endif
#if defined(_LINUX)
#include <pthread.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdio.h>
#endif
(2)各自实现
#if defined(_LINUX)
_threadwraper_t* pthreadwraper = new _threadwraper_t[1];
pthreadwraper[0].proc = proc;
pthreadwraper[0].pargs = pargs;
pthreadwraper[0].sem_flag = 0;
return pthread_create(&ntid, &pth_attr, _ThreadWraper_Linux, pthreadwraper);
#endif
#if defined(_WINDOWS)
_threadwraper_t* pthreadwraper = new _threadwraper_t[1];
pthreadwraper[0].proc = proc;
pthreadwraper[0].pargs = pargs;
pthreadwraper[0].hThread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)proc, pargs, 0, &pthreadwraper[0].dwId);
return pthreadwraper;
#endif