谁可以帮忙看下这个C++程序的问题!!

来源:百度知道 编辑:UC知道 时间:2024/05/20 06:21:27
程序代码如下:
#include <windows.h>
#include <iostream.h>

DWORD WINAPI Fun1Proc(LPVOID lpParameter);
DWORD WINAPI Fun2Proc(LPVOID lpParameter);

HANDLE hMutex;

void main()
{
HANDLE hThread1=CreateThread(NULL,0,Fun1Proc,NULL,0,NULL);
HANDLE hThread2=CreateThread(NULL,0,Fun2Proc,NULL,0,NULL);

CloseHandle(hThread1);
CloseHandle(hThread2);

hMutex=CreateMutex(NULL,TRUE,"tickets");
if(hMutex)
{
if(ERROR_ALREADY_EXISTS==GetLastError())
{
cout<<"only one instance can run!"<<endl;
return;
}
}
ReleaseMutex(hMutex);
Sleep(10000000);
}
DWORD WINAPI Fun1Proc(LPVOID lpParameter)
{
WaitForSingleObject(hMutex,INFINITE);
cout<<"thread1 is running"<<endl;
return 0;
}

DWORD WINAPI Fun2Proc(LPVOID lpParameter)
{
WaitForSingl

把这段移动到main后,CreateThread之前就好了
hMutex=CreateMutex(NULL,TRUE,"tickets");
if(hMutex)
{
if(ERROR_ALREADY_EXISTS==GetLastError())
{
cout<<"only one instance can run!"<<endl;
return;
}
}
ReleaseMutex(hMutex);
Sleep(10000000);
}

楼主是怎么跑的,不知所云!!!!!!!!!!!