www.pudn.com > PC_final.rar > ProducerThread.cpp


// ProducerThread.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "PC.h" 
#include "ProducerThread.h" 
#include "PCDlg.h" 
 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CProducerThread 
 
IMPLEMENT_DYNCREATE(CProducerThread, CWinThread) 
 
//##ModelId=48595303036C 
CProducerThread::CProducerThread() 
{ 
} 
//##ModelId=48595303036D 
CProducerThread::CProducerThread(void* mParent,CString name) 
{ 
	this->m_Parent=mParent; 
	this->m_name=name; 
} 
//##ModelId=48595303038B 
CProducerThread::~CProducerThread() 
{ 
} 
 
//##ModelId=48595303037C 
BOOL CProducerThread::InitInstance() 
{ 
	// TODO:  perform and per-thread initialization here 
	return TRUE; 
} 
 
//##ModelId=48595303037E 
int CProducerThread::ExitInstance() 
{ 
	// TODO:  perform any per-thread cleanup here 
	return CWinThread::ExitInstance(); 
} 
 
BEGIN_MESSAGE_MAP(CProducerThread, CWinThread) 
//{{AFX_MSG_MAP(CProducerThread) 
// NOTE - the ClassWizard will add and remove mapping macros here. 
//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CProducerThread message handlers 
 
//##ModelId=485953030380 
int CProducerThread::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; 
	while(pDlg->m_continue){ 
        DWORD temp=WaitForMultipleObjects(SIZE_OF_BUFFER,pDlg->m_hEmptySemaphore,FALSE,INFINITE); 
		pDlg->m_PArray[temp]=1; 
		pDlg->m_PStr[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]=1; 
		pDlg->m_PArray[temp]=0; 
		pDlg->m_PStr[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_hFullSemaphore[temp],1,NULL); 
		Sleep(t*100); 
    } 
	this->ExitInstance(); 
	return CWinThread::Run(); 
}