게임서버
ReaderWriterLock 구현 연습
namespace ServerCore { //재귀적 락을 허용할지 (yes) writeLock ->writeLock (ok) ,writelock->readlock (ok) ,readlock ->writelock (no) //재귀적 락을 허용할지 (NO) //스핀락 정책 (5000번 ->Yield) class Lock { const int EMPTY_FLAG = 0x00000000; const int WRITE_MASK = 0x7FFF0000; const int READ_MASK = 0x0000FFFF; const int MAX_SPIN_COUNT = 5000; // [Unused (1비트)] [WriteThreadId (15비트)] [ReadCount (16비트)] int flag= EMPTY_FLAG;..
하드웨어 최적화
class Program { static int x = 0; static int y = 0; static int r1 = 0; static int r2 = 0; static void Thread_1() { y = 1; //Store y r1 = x; //Load x } static void Thread_2() { x = 1; //Store y r2 = y; //Load x } static void Main(string[] args) { int count = 0; while (true) { count++; x = y = r1 = r2 = 0; Task t1 = new Task(Thread_1); Task t2 = new Task(Thread_2); t1.Start(); t2.Start(); Task.Wai..
컴파일러 최적화
namespace 최적화 { class Program { static bool _stop = false; //동시 접근 가능 static void ThreadMain() { Console.WriteLine("쓰레드 시작!"); while (_stop == false) { //stop 신호를 기다림 } Console.WriteLine("쓰레드 종료!"); } static void Main(string[] args) { Task t = new Task(ThreadMain); t.Start(); Thread.Sleep(1000); _stop = true; Console.WriteLine("Stop 호출"); Console.WriteLine("종료 대기중"); t.Wait(); Console.WriteLine(..
쓰레드 기초
개론 프로세스 = 프로그램 쓰레드 = 프로그램 안에서 일하는 직원 CPU코어 = 직원에게 명령을 내림 * CPU코어 1개 / 쓰레드 여러 개인 상황 : 코어가 아주 짧은 시간 번갈아 가면서 쓰레드에게 명령을 내림 쓰레드 생성 using System; using System.Threading; namespace ServerCore { class Program { static void MainThread() { Console.WriteLine("Hello Thread!"); } static void Main(string[] args) { Thread t = new Thread(MainThread); //정직원 고용 t.Start(); //일 시작 Console.WriteLine("Hello World!");..