게임서버/멀티쓰레드 이론(10)
-
Thread Design3과 잡다한얘기
안녕하세요 대학생 개발자입니다. 저번 글에서는 IO를 완료한 스레드가 직접 로직에 개입을하는 그런 스레드 디자인을 알아봤습니다. 그리고 IO스레드와 따로 메시지를 처리하는 스레드와 월드의 프레임을 돌려주는 스레드를 분리한 디자인과의 차이점도 확인을 했었습니다. 그리고 가장 중요한 어떤 디자인이 더 효율적이고 더 좋은 디자인인지에 대한 논의를 해봤었습니다. 이번글에서는 헤테로 지니어스와 호모 지니어스에 대한 얘기를 해볼겁니다. 물론 이얘기는 진작 언급 했어야 됬지만 이때까지의 구조는 거의 모두 호모지니어스에 가까운 구조였습니다. 먼저 그럼 시작에 앞서서 이부분에 대해서 짚고 넘어가겠습니다. 워커 스레드들이 있을 때 우리는 이 워커 스레드들이 어떠한 작업을 할지 알려줘야 됩니다. 하나의 스레드는 하나의 함수..
2022.02.09 -
Thread Design2
안녕하세요 대학생 개발자입니다. 저번 글에서는 쓰레드 디자인에 대해서 좀 정리를 해봤었습니다. 우선 이전 글에서는 이런 내용들이 있었습니다. 베이스는 무조건 멀티스레드 IOCP로 송수신 처리를 하는 겁니다. IO처리(비동기 recv겠죠)가 완료된 후에는 일거리(잡)들을 업데이트 서버의 큐에 넣어주는 방식이었습니다. 그럼 업데이트를 하는 서버는 큐에서 하나씩 꺼내서 사용하는 방식으로 작동했었는데요. 여기서 서버 월드를 돌리는 메인루프 스레드와 메시지 처리부 스레드가 하나였기 때문에 싱글스레드 서버라고 했었습니다. 그리고 만약 서버에 부하가 큰 로직(길찾기, 물리엔진, AI등)을 처리할땐 그 쓰레드를 분리한다고 했습니다. 추가로 그 쓰레드는 메인 루프를 처리하는 쓰레드에게 최소한의 부하를 주기 위해서 조력하..
2022.02.04 -
Thread Design
안녕하세요 대학생 개발자입니다. 저번 글에서는 피터슨 알고리즘을 끝으로 마무리를 지었었는데요... 이번 글에서도 피터슨 알고리즘에 대해서 조금 마무리를 짓고 나서 스레드 디자인으로 넘어가 보겠습니다. 피터슨 알고리즘이란 이런 것이죠. 언어적 차원에서의 논리적인 문제가 전혀 존재하지 않음에도 불구하고 cpu의 out of ordering excution에 의해서 load와 store의 순서가 뒤바뀌게 되고 그 뒤바뀜으로 인해서 결과가 이상해지는 그런 경우였던 거였죠... 근데 이 부분은 고칠 수 있을 것 같이 들립니다. { flag0 = true turn = 0; while(flag1 == true && turn == 0); } 바로 위 코드에서 문제가 되는 상황인 flag1이 load 되는 게 turn의..
2022.01.27 -
Out Of Ordering Excution
안녕하세요 대학생 개발자입니다. 저번 글에서는 동기화와 관련된 얘기를 계속 했었습니다. 이번글에서는 out of ordering excution에 대한 정리를 할겁니다. 우선 저 글을 정리하기 이전에 저번 글에서 마져 다 소개하지 못했던 내용들을 정리해놓고 시작하도록 하겠습니다. 저 그럼 시작하겠습니다. Event에 대한 얘기를 하고서는 마감을 했었던 것으로 기억합니다. 어떤 함수를 동기로 처리한다 라고 하면 이런 구조로 처리가 됩니다. ----|A:(return)|---- 저 사이구간은 다른 작업을 하지 못하고 A라는 함수에만 매달려 있어야 하므로 동기 함수라고 할 수 있죠. 근데 이걸 비동기화 시키고 싶다면 예전 같은 경우에는 ----(AThread생성)----- ---(A)---(return) 와 ..
2022.01.24 -
Synchronization2
안녕하세요 대학생 개발자입니다. 저번 글에서는 동기화에 대한 얘기와 동기화 객체에 대한 얘기를 간단히 했습니다. 오늘할 얘기도 별반 다르지 않습니다. 다만 다른점은 이번에 다룰 WaitOnAddress는 객체는 아니라는점이죠 ㅋㅋㅋㅋㅋ 주소를 가지고 기다리는 거니까... 객체는 아니잖아요? 어째뜬 시작해보도록 하겠습니다 WaitOnAddress가 뭔지 간단히 파헤쳐 보겠습니다. WaitOnAddress 방식의 동기화는 동기화 객체의 방식처럼 뭔가를 획득하고 안되고라는 개념은 아닙니다. 나는 어느 주소를 대상으로 기다리고 있을테니 니가 준비가 되면 나를 깨워줘의 느낌입니다. 네 그리고 WaitOnAddress의 경우에는 이 하나만 가지고는 동기화를 보장할 수 없습니다. 왜냐면... 주소를 기준으로 기다리기..
2022.01.21 -
Synchronization
안녕하세요 대학생 개발자입니다. 오늘은 시간이 많이 남아서 두번째글을 연달아서 쓰고있습니다. 이런날이 언제쯤 또 올수있을지... 한동안 해야할 일이 너무 많았기 때문에 바빳는데... 좋습니다 그럼 시작하겠습니다 저번 글에서는 쓰레드에 대한 얘기를 했었습니다. 쓰레드를 사용할때 어떤점을 주의해야되고 어떤점이 있으니 참고해야된다고 말씀드렸었는데요... 이번시간에는 쓰레드들간에 같은 공유자원을 사용할 때 어떤식으로 공유자원의 동기화를 걸 수있는지 몇가지 방법에 대해서 소개를 할겁니다. 그리고 동기화를 하는 알고리즘 몇가지를 소개할 예정입니다. 자 그러면 시작하겠습니다. 먼저 cpu차원에서의 동기화인 인터락 함수에 대해서 알아보겠습니다. 인터락이라는 것은 먼저 아주 간단하게 보자면 최소단위의 연산을 cpu가 보..
2022.01.21 -
Thread
안녕하세요 대학생 개발자입니다. 저번 글에서 동기화 객체에 대한 얘기를 했고 조금 짧은 글이었습니다.왜냐면... 이번글부터 쓰레드 부분인데 사실 쓰레드 부분에 들어가는 순간 어디서 끊어야할지 매우 난감하기 떄문에 중간에 한번 끊고 갈 수 밖에 없었던 부분입니다... 그리고 이번글을 시작하기전에 이번글의 표지사진은 이번글과는 관계가 없음을 알려드립니다. 멀티쓰레드에 대한 얘기를 해야되는데 아직 쓰레드에 대한 얘기도 못꺼냈습니다 ㅋㅋㅋ... 무려 4번째 글만에 드디어 쓰레드라는 제목을 달고 나왔긴 하지만... 사실 이글에서 쓰레드에 대한 모든부분을 다루지는 못할거에요... 그럼 일단 시작해보겠습니다.윈도우는 쓰레드 스케쥴링을 하는 os입니다. 물론 요새는 거의 대부분os가 쓰레드를 스케쥴링하는것으로 알고있습..
2022.01.20 -
Synchronization object
안녕하세요 대학생 개발자입니다. 제가 졸업하기까지 이제 거의 한달정도 남았는데 닉네임을 뭐로 바꿔야하는지 참고민이 많습니다... 그것보다 닉네임은 그렇다 치더라고... 블로그 주소는 어찌합니까... 이런 고민들이 참 많습니다... 째뜬 이건 중요하지 않습니다 중요한건 오늘 할 내용이겠죠 자 보면 저번 글에서까지 윈도우즈의 스케쥴링과 컨텍스트 스위칭에 대해서 간단히 알아봤습니다. 저부분에 관한건 계속 언급될겁니다 매우 중요하기 때문이죠... 일단 동기화 객체에 얘기하기 전에 동기화 객체가 왜 필요한지에 대한 언급이 먼저 나와야 될 것 같습니다. int g_Counter; void WorkerThread() { for(int i=0; i< 1000000 ; i++) g_Counter++; } 이런 코드가 있..
2022.01.19 -
windows scheduling
안녕하세요 대학생 개발자입니다. 이번 글에서는 저번 글에 이어서 윈도우즈의 스케쥴링 방식에 대해서 얘기를 더 해볼겁니다. 우선 스케쥴링이란게 뭔지 알아야될겁니다. 스케쥴링이란건... 뭐 간단히 따지면 어떤 쓰레드를 실행할 것이냐에 대한 부분인거겠죠 스케쥴링의 주체가 누구인지를 먼저 알아야 될 것 같은데요... 사실 윈도우가 스케쥴링 한다가 맞는말이겠지만... 좀더 구체적으로 어떤 계기로 스케쥴링이 발생하느냐 그리고 누가 직접 스케쥴링을 하느냐 에 대한 부분을 따지고 든다면 cpu자체가 스케쥴링의 주체이자 대상이 될겁니다. 무슨말인지 잘 이해가 안되실 수도있습니다. 간단히 설명하면 os는 코드에 불과합니다 결국 코드라는건 하드웨어 의존없이 혼자서 작동될 수 없는 것인데요... 결국 os의 스케쥴링이란것도 ..
2022.01.19 -
Windows preemptive priority based round-robin scheduling
안녕하세요 대학생 개발자입니다 이전 글에서는 싱글 스레드로 구현할 수 있는 간단한 mmo타입의 게임을 만들어봤습니다. 이번 글에서는 게임 서버 개발자가 되면 주로 접하게될 Windows Server, 즉 Windows OS에 대한 얘기를 해보려고합니다. os에 따라 내용이 다른 부분이 있을 수 있으니, 미리 Windows를 상정하고 말씀드린다는 부분 양해부탁드립니다. preemptive 우선 선점에 대한 개념부터 정리를 하고 넘어가겠습니다. 우선 우리가 일반적으로 사용하는 windows os는 선점형이냐 비선점형이냐 라는 부분인데요. 하지만 이 전에 우리가 먼저 따져봐야할 부분이 있습니다. 선점의 주체가 누가 되는것인가 입니다. OS가 선점의 주체가 된다면 스레드들은 OS의 관리를 받는 주체가 될 것입니..
2022.01.18