www.pudn.com > PC_final.rar > ConsumerThread.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=4859530400CC 
CConsumerThread::CConsumerThread() 
{ 
} 
//##ModelId=4859530400CD 
CConsumerThread::CConsumerThread(void *pParent,CString name) 
{ 
	this->m_Parent=pParent; 
	this->m_name=name; 
} 
//##ModelId=4859530400FA 
CConsumerThread::~CConsumerThread() 
{ 
} 
 
//##ModelId=4859530400DB 
BOOL CConsumerThread::InitInstance() 
{ 
	// TODO:  perform and per-thread initialization here 
	return TRUE; 
} 
 
//##ModelId=4859530400DD 
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=4859530400DF 
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(); 
}