www.pudn.com > c++或C下如何使用多线程.zip > CounterThread.cpp
// CounterThread.cpp: implementation of the CCounterThread class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "TrdDemo.h"
#include "CounterThread.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CCounterThread::CCounterThread()
{
}
CCounterThread::CCounterThread(int nThreadId)
{
m_nThreadId = nThreadId;
}
CCounterThread::~CCounterThread()
{
}
void CCounterThread::BeginProcess()
{
EnterCriticalSection(&CBaseThread::m_csNumLock);
{
TRACE2("Thread %d says: hi, m_nCounter is now %d.\n",
m_nThreadId, ++m_nCounter);
}
LeaveCriticalSection(&CBaseThread::m_csNumLock);
Sleep(300);
}