?? cworkerthreadhandler.cpp
字號(hào):
//
// FILE: CWorkerThreadHandler.cpp
//
// Copyright (c) 1997 by Aaron Michael Cohen and Mike Woodring
//
/////////////////////////////////////////////////////////////////////////
#include "CWorkerThreadHandler.h"
#include <stdio.h>
// CWorderThreadHandler implementation.
//
CWorkerThreadHandler::CWorkerThreadHandler( CMclEvent& ExitEvent, BOOL fFault )
: m_ExitEvent(ExitEvent),
m_fFault(fFault)
{
}
unsigned CWorkerThreadHandler::ThreadHandlerProc( void )
{
srand(GetCurrentThreadId());
printf(
"[0x%08lx] Worker thread is starting up (%s fault).\n",
GetCurrentThreadId(),
(m_fFault ? "will" : "will not")
);
int iWorkCount = 0;
BOOL fKeepWorking = TRUE;
while( fKeepWorking )
{
// Do some work.
//
printf(
"[0x%08lx] Worker thread is doing work.\n",
GetCurrentThreadId()
);
iWorkCount++;
// Sleep for one second by waiting for the exit event
// to be signaled. If we time out, we'll keep working.
// If we don't time out, we'll cleanup and exit.
//
DWORD dwWaitResult = m_ExitEvent.Wait(1000);
fKeepWorking = CMclWaitTimeout(dwWaitResult);
if( fKeepWorking )
{
// Check to see if this thread should fault.
//
if( m_fFault && (iWorkCount == 4) )
{
printf(
"[0x%08lx] Worker thread is about to fault.\n",
GetCurrentThreadId()
);
*((PBYTE)0) = '!';
}
}
}
printf(
"[0x%08lx] Worker thread is exiting.\n",
GetCurrentThreadId()
);
return(0);
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -