源代码:
#include
#include
#include
using namespace std;
int tickets=100;
HANDLE hMutex;
class MyThread
{
private:
char name;
HANDLE hThread;
public:
MyThread(char name2)
{
name=name2;
hThread=CreateThread(NULL,0,FunProc,NULL,0,NULL);
}
DWORD WINAPI FunProc(LPVOID lpParameter)
{
while (true)
{
WaitForSingleObject(hMutex,INFINITE);
if (tickets>0)
{
printf("%c:%d",name,tickets);
tickets=tickets-1;
}
else
{
break;
}
ReleaseMutex(hMutex);
}
return 0;
}
~MyThread()
{
CloseHandle(hThread);
}
};
void main(){
char x,y,z;
hMutex=(HANDLE)CreateMutex(NULL,FALSE,NULL);
MyThread thread_x(x);
MyThread thread_y(y);
MyThread thread_z(z);
Sleep(5000);
}
报错是这样的:
error C3867: “MyThread::FunProc”: 函数调用缺少参数列表;请使用“&MyThread::FunProc”创建指向成员的指针