인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

Inflearn Community Q&A

김영훈's profile image
김영훈

asked

[MMORPG Game Development Series with C++ and Unreal] Part 4: Game Server

Event

event 관련 질문 있습니다.

Written on

·

367

0

동일한 내용으로 동일한 코드를 쳤는데 디버그로 cpu 점유율 확인시 저는 똑같이 8% 가 나오는데 혹시 어떤 부분에서 이러한 차이가 나는지 알 수 있을까요?

 

mutex m;
queue<int32> q;
HANDLE handle;

void Producer()
{
	while (true)
	{
		{
			unique_lock<mutex> lock(m);
			q.push(100);
		}

		::SetEvent(handle);

		this_thread::sleep_for(10000ms);
	}
}

void Consumer()
{
	while (true)
	{
		::WaitForSingleObject(handle, INFINITY);
		unique_lock<mutex> lock(m);
		if (q.empty() == false)
		{
			int32 data = q.front();
			q.pop();
			cout << data << endl;
		}
	}
}

int main() 
{
	handle = ::CreateEvent(NULL/*보안속성*/, FALSE/*bManualReset*/, FALSE/*bInitialState*/, NULL);

	thread t1(Producer);
	thread t2(Consumer);

	t1.join();
	t2.join();

	::CloseHandle(handle);
}
MMORPGwindows-servernetwork

Answer 1

1

rookiss님의 프로필 이미지
rookiss
Instructor

이 부분은 컴퓨터 환경에 따라 상이해 저도 알기 힘듭니다.

김영훈's profile image
김영훈

asked

Ask a question