본문 바로가기

C#20

[C#] IComparable과 IComparer public class Number : IComparable { public int value = 0; public Number(int num) { this.value = num; } public int CompareTo(Number? other) { if (this.value > other.value) { return 1; } else if (this.value y.value) { return -1; } else if (x.value.. 2023. 3. 26.
[C#] Dispose 패턴 public class ResourceBase : IDisposable { private bool disposedValue; protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { // TODO: 관리형 상태(관리형 개체)를 삭제합니다. } // TODO: 비관리형 리소스(비관리형 개체)를 해제하고 종료자를 재정의합니다. // TODO: 큰 필드를 null로 설정합니다. disposedValue = true; } } ~ResourceBase() { Dispose(disposing: false); } public void Dispose() { Dispose(disposing: true); // this에 .. 2023. 3. 23.
[C#] Interlocked 그 이유는 이를 해결하기 위해선, Interlocked 클래스는 하드웨어 시그널을 통해 다른 CPU가 해당 메모리에 접근하지 못하도록 막는다고 함. https://jungwoong.tistory.com/41 [window c++] InterLocked 함수들 스레드 동기화가 필요한 이유 스레드에 관련된 글에서 설명 한 것 처럼 프로세스에 속한 스레드들은 프로세스의 리소스 자원을 공유합니다. 또한 시스템의 힙, 파일, 윈도우등등 많은 시스템 리 jungwoong.tistory.com https://learn.microsoft.com/ko-kr/dotnet/api/system.threading.interlocked?view=net-7.0 2023. 3. 20.
[C#] 메모리 베리어 예제 class Program { static int x = 0; static int y = 0; static int r1 = 0; static int r2 = 0; static void Main(string[] args) { int count = 0; while(true) { count++; x = y = r1 = r2 = 0; Task t1 = new Task(Thread1); Task t2 = new Task(Thread2); t1.Start(); t2.Start(); Task.WaitAll(t1, t2); if (r1 == 0 && r2 == 0) break; } Console.WriteLine($"{count}번만에 루프 탈출"); } static void Thread1() { y = 1; Threa.. 2023. 3. 6.