intarray.cpp

来自「《Visual C++ 6.0实例教程》配套代码」· C++ 代码 · 共 46 行

CPP
46
字号
// IntArray.cpp: implementation of the CIntArray class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "ThreadTest.h"
#include "IntArray.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CIntArray::CIntArray()
{
	semaphore = new CSemaphore(2, 2);

}

CIntArray::~CIntArray()
{
	delete semaphore;
}

void CIntArray::SetArray(int value)
{
	CSingleLock singleLock(&mutex);
	singleLock.Lock();
	for (int x=0; x<10; ++x)
		array[x] = value;
}

void CIntArray::GetArray(int dstArray[10])
{
	CSingleLock singleLock(semaphore);
	singleLock.Lock();
	for (int x=0; x<10; ++x)
		dstArray[x] = array[x];
	Sleep(2000);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?