24,854
社区成员
发帖
与我相关
我的任务
分享
#include <windows.h>
#include "semaphore.h"
#include "thread.h"
#include <iostream>
using namespace std;
Semaphore mutex(1);
//unsigned int WINAPI hello(void * param){
unsigned int WINAPI hello(int param){
while(TRUE){
mutex.P();
cout << GetCurrentThreadId() << " says hello ."<<endl;
mutex.V();
Sleep(rand()%1000);
}
}
int main(){
HANDLE hThread[2];
hThread[0] = startThread(hello(1),NULL);
hThread[1] = startThread(hello(2),NULL);
::WaitForMultipleObjects(2,hThread,TRUE,INFINITE);
CloseHandle(hThread[0]);
CloseHandle(hThread[1]);
return 0;
}
我是实行这段代码,发现需要semaphore.h,然后直接下这个头文件,复制到编译出来的文件里,编译器又说缺少cdefs.h,我又下了这个头文件,但不知道把它放哪里
#include "semaphore.h"
Semaphore mutex(1);
semaphore.h应该不是系统头文件。
2. 设置工程属性INCLUDE,可以修改编译器头文件搜索路径。 不要第三方头文件放在系统路径中。