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

📄 ~consumerthread.~cpp

📁 有关操作系统课程设计的代码
💻 ~CPP
字号:
// ConsumerThread.cpp : implementation file
//

#include "stdafx.h"
#include "PC.h"
#include "ConsumerThread.h"
#include "PCDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CConsumerThread

IMPLEMENT_DYNCREATE(CConsumerThread, CWinThread)

//##ModelId=4859317403C9
CConsumerThread::CConsumerThread()
{
}
//##ModelId=4859317403CA
CConsumerThread::CConsumerThread(void *pParent,CString name)
{
	this->m_Parent=pParent;
	this->m_name=name;
}
//##ModelId=485931750002
CConsumerThread::~CConsumerThread()
{
}

//##ModelId=4859317403DB
BOOL CConsumerThread::InitInstance()
{
	// TODO:  perform and per-thread initialization here
	return TRUE;
}

//##ModelId=4859317403DD
int CConsumerThread::ExitInstance()
{
	// TODO:  perform any per-thread cleanup here
	return CWinThread::ExitInstance();
}

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

/////////////////////////////////////////////////////////////////////////////
// CConsumerThread message handlers

//##ModelId=485931750000
int CConsumerThread::Run() 
{
	// TODO: Add your specialized code here and/or call the base class
	CPCDlg *pDlg;
	pDlg=(CPCDlg*)this->m_Parent; 
	int temp=0;
	int t=0;

	CString str;

	while(pDlg->m_continue){
        DWORD temp=WaitForMultipleObjects(SIZE_OF_BUFFER,pDlg->m_hFullSemaphore,FALSE,INFINITE);
		pDlg->m_CArray[temp]=1;
		pDlg->m_CStr[temp]=this->m_name;
		pDlg->InvalidateRect(CRect(17+temp*40,17,20+(temp+1)*40,200));
		srand( (unsigned)time( NULL ) ); 
	    t=rand()%5;
		t+=1;
		Sleep(t*750+500);
		pDlg->m_Array[temp]=0;
		pDlg->m_CArray[temp]=0;
		pDlg->m_CStr[temp]="";
		pDlg->InvalidateRect(CRect(17+temp*40,17,20+(temp+1)*40,200));
		srand( (unsigned)time( NULL ) ); 
	    t=rand()%10;
		t+=10;
		ReleaseSemaphore(pDlg->m_hEmptySemaphore[temp],1,NULL);
		Sleep(t*100);




   }
	this->ExitInstance();
	return CWinThread::Run();
}

⌨️ 快捷键说明

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