#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;
}

 

相关文章:

  • 2021-09-08
  • 2021-12-04
  • 2021-08-22
  • 2021-11-27
  • 2022-01-25
  • 2021-10-02
  • 2021-05-20
猜你喜欢
  • 2022-12-23
  • 2021-07-19
  • 2021-09-25
  • 2021-07-14
  • 2022-02-13
  • 2022-02-15
  • 2021-12-17
相关资源
相似解决方案