📄 consumerthread.event
字号:
/************************************************************************
* 版权所有 (C)2003,windcao(曹建峰)
* 作 者: 曹建峰
* 完成日期: 2004年1月9日
* 修改日期 版本号 修改人 修改内容
************************************************************************/
// ConsumerThread.cpp : implementation file
//
#include "stdafx.h"
#include "P_C.h"
#include "ConsumerThread.h"
#include "P_CDlg.h"
#include <afxmt.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CConsumerThread
IMPLEMENT_DYNCREATE(CConsumerThread, CWinThread)
CConsumerThread::CConsumerThread()
{
}
CConsumerThread::CConsumerThread(void *pParent):m_pParent(pParent)
{
}
CConsumerThread::~CConsumerThread()
{
}
BOOL CConsumerThread::InitInstance()
{
// TODO: perform and per-thread initialization here
return TRUE;
}
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
int CConsumerThread::Run()
{
// TODO: Add your specialized code here and/or call the base class
CP_CDlg *pDlg;
pDlg=(CP_CDlg*)this->m_pParent;
char*pBuf;
pBuf=this->m_Data;
CMutex *pMutex;
CEvent *pFull;
CEvent *pEmpty;
pFull=new CEvent(true,true,"BufFull");
pEmpty=new CEvent(true,true,"BufEmpty");
pMutex =new CMutex(true,"PC_Mutex");
CSingleLock mutexLock(pMutex);//,FullLock(pFull ),EmptyLock(pEmpty);
//CSemaphore* m_pSemaphoreEmpty;
//CSemaphore* m_pSemaphoreFull;
//m_pSemaphoreFull =new CSemaphore(1,1,"SemaphoreFull");
//m_pSemaphoreEmpty =new CSemaphore(0,1,"SemaphoreEmpty");
//this->m_pActiveWnd->MessageBox(m_Data);
const int bufWidth=10;
const int ShowWidth=5000;
for(int i=0;i<1000000&&pBuf<(m_Data+CSM_BUF_COUNT-10);i+=bufWidth)
{
//FullLock.Lock();
::WaitForSingleObject(pFull,INFINITE);
mutexLock.Lock();
sprintf(pBuf,pDlg->m_sBuf.GetBuffer(0));
mutexLock.Unlock();
pBuf+=bufWidth;
m_Data[ShowWidth]=0;
mutexLock.Lock();
sprintf(pDlg->m_sBufCSM.GetBuffer(0),m_Data);
// sprintf(pDlg->m_sBufCSM.GetBuffer(0),"tt");
mutexLock.Unlock();
pFull->SetEvent();
// pEmpty->SetEvent();
//EmptyLock.Unlock();
}
// this->m_pActiveWnd->MessageBox(m_Data);
// this->m_pActiveWnd->MessageBox("cr");
return CWinThread::Run();
}
void CConsumerThread::KillSelf()
{
if(this->m_hThread)
{
VERIFY( ::CloseHandle(this->m_hThread) );
}
//delete this;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -