⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testthread.cpp

📁 适合初学者
💻 CPP
字号:
// TestThread.cpp : implementation file
//

#include "stdafx.h"
#include "Test02.h"
#include "TestThread.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTestThread

IMPLEMENT_DYNCREATE(CTestThread, CWinThread)

CTestThread::CTestThread()
{
	m_brun=true;
}

CTestThread::~CTestThread()
{
}

BOOL CTestThread::InitInstance()
{
	// TODO:  perform and per-thread initialization here
	return TRUE;
}

int CTestThread::ExitInstance()
{
	// TODO:  perform any per-thread cleanup here
	return CWinThread::ExitInstance();
}

BEGIN_MESSAGE_MAP(CTestThread, CWinThread)
	//{{AFX_MSG_MAP(CTestThread)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestThread message handlers

int CTestThread::Run() 
{
	// TODO: Add your specialized code here and/or call the base class
	//ms 以下这个循环写的好,是一个永真的程序,进而只要满足m_brun为真则就运行
	//ms且中间的间隔是2秒钟
	/************************************************************************/
	/* ms 这是表示的是用锁的形式抢占资源,但锁用的是另一个变量,与其他的过程没有联系
	只是在用到哪个变量(A)的时候就用锁变量(B)将该变量(A)锁上,用完后就打开锁
	从复控的程序看这种方法是对的,就是用一个变量专门是锁的作用*/
	/************************************************************************/
	while(1)
	{
		if(m_brun)
		{
			AfxMessageBox("RUN");
			m_mrun.Lock();
			m_brun=TRUE;
		//MessageBox(NULL,"111","",NULL);
			m_mrun.Unlock();
		}
		Sleep(2000);
	}
	
	return CWinThread::Run();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -