안다고 생각했던 게 헷갈릴 때가 있다.
What happens if two threads read & write the same piece of memory
It's my understanding that if two threads are reading from the same piece of memory, and no thread is writing to that memory, then the operation is safe. However, I'm not sure what happens if one t...
stackoverflow.com
C# 같은 언어의 경우 일부 자료형은 항상 atomic 하게 연산되기도 한다. 하지만 그렇다 하더라도 volatile 을 사용하면 성능이 저하될 수 있고 캐시의 값이 메모리에 즉시 반영되지 않을 수도 있는 문제 때문에 결국 락을 걸던가 해야한다.
https://learn.microsoft.com/en-us/dotnet/api/system.threading.interlocked.increment
Interlocked.Increment Method (System.Threading)
Increments a specified variable and stores the result, as an atomic operation.
learn.microsoft.com
https://learn.microsoft.com/en-us/dotnet/api/system.threading.volatile
Volatile Class (System.Threading)
Contains methods for performing volatile memory operations.
learn.microsoft.com
'D' 카테고리의 다른 글
클라우드의 전용 호스트 (0) | 2023.12.05 |
---|---|
AWS, Azure, Google Cloud 의 서로 대응되는 서비스 (0) | 2023.11.29 |
레이턴시를 연출로 처리 (0) | 2023.11.16 |
소켓에 bind 하는 주소는 any로 지정해야 한다 (0) | 2023.11.11 |
TCP 최대 연결 수 (0) | 2023.11.08 |