一点代码

#include <iostream>
#include <afxwin.h>
using namespace std;


static UINT OnThreadFunc(LPVOID p);
HANDLE nMetux;
HANDLE nThread1;
void main()
{
	cout<<"The host thread is called"<<endl;
	cout<<"---------------------------------------------------------"<<endl;

	nMetux = CreateMutex(NULL,TRUE,NULL);
	nThread1 =AfxBeginThread(OnThreadFunc,NULL);
	Sleep(15000);
	cout<<"线程结束"<<endl;
	cout<<"---------------------------------------------------------"<<endl;

}

UINT OnThreadFunc(LPVOID p)
{
	WaitForSingleObject(nMetux,10000);
    
	cout<<"The second thread id called"<<endl;
	for(int i = 0;i<10;i++)
	{
		cout<<endl;
	}
	ReleaseMutex(nMetux);
	return 1;
}
原文地址:https://www.cnblogs.com/CBDoctor/p/2837670.html