강의

멘토링

커뮤니티

Inflearn Community Q&A

besamly20188204's profile image
besamly20188204

asked

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

Memory model

atomic 클래스를 다른 클래스와 사용한다면

Written on

·

352

0

atomic<int> atomic_int의 수정은 atomic_int.store() 함수를 이용해서 atomic하게 값 assignment가 가능한데
 
예를 들어 직접 정의한 Person 클래스의 name등과 같은 여러 맴버변수를 atomic하게 수정할 때 사용하는 함수가 있을까요?
networkMMORPGwindows-server

Answer 1

1

Rookiss님의 프로필 이미지
Rookiss
Instructor

우선 atomic<T>를 이용한다 하더라도 '정말' CPU에서 지원하는 단일 연산으로 
lock_free하게 된다는 보장까진 없습니다.
is_lock_free 함수를 이용해 현재 타입에 대해 '정말 CPU에서 연산을 지원하는지' 체크해볼 수 있구요.

Person 클래스의 name과 같이 여러 정보를 수정해야 할 경우,
atomic 클래스보단 lock을 거는 쪽으로 생각을 해야 합니다.

besamly20188204's profile image
besamly20188204

asked

Ask a question