강의

멘토링

커뮤니티

Inflearn Community Q&A

deany01312603's profile image
deany01312603

asked

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

Reference Counting의 멀티 쓰레드 환경에 대해서 질문이 있습니다.

Resolved

Written on

·

465

0

Reference Counting의 코드가 멀티 쓰레드 환경에서 잘 작동한다고 말씀해주셨습니다.

 

제가 코드를 공부하고 있는데, RefCounting.h의

	inline void Set(T* ptr)
	{
		_ptr = ptr;
		if (ptr)
			ptr->AddRef();
	}

이 부분에서 if(ptr)은 통과를 했는데, ptr->AddRef()를 하기 직전에, 해당 ptr이 Release 되어서 nullptr이 되버린다면, nullptr의 AddRef()를 호출함으로 오류가 뜰 수 있다고 생각이 되었습니다.

이렇게 된다면 멀티 쓰레드 환경에서 잘 작동하지 않는다고 생각이 들었는데, 제가 수업을 들으면서 무언가 놓친 것이 있는 걸까요?

 

네트워크MMORPGwindows-server

Answer 1

0

Rookiss님의 프로필 이미지
Rookiss
Instructor

잘 동작하지 않는다고 말을 했을거에요 대안이 sharedptr입니다

deany01312603님의 프로필 이미지
deany01312603
Questioner

헉! 제가 잘못 알아들었네요 ㅜㅜ

늦은 시간인데도 이렇게 글을 봐주셔서 감사합니다!

deany01312603's profile image
deany01312603

asked

Ask a question