• 카테고리

    질문 & 답변
  • 세부 분야

    게임 프로그래밍

  • 해결 여부

    미해결

event 관련 질문 있습니다.

22.12.29 23:33 작성 조회수 265

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);
}

답변 1

답변을 작성해보세요.

1

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