프로그래밍/CS
2024. 9. 19.
[Study] 뮤텍스 (Mutex)
뮤텍스(Mutex)란? : 뮤텍스(Mutex)는 Mutual Exclusion의 줄임말로, 다중 스레드 환경에서 공유 자원에 대한 동시 접근을 방지하기 위한 동기화 매커니즘이다. 뮤텍스를 사용하면 여러 스레드가 동시에 공유 자원에 접근하지 못하게 해 데이터 경합이나 데이터 불일치 문제를 방지할 수 있다.뮤텍스의 필요성 : 프로그램에서 여러 스레드가 동시에 실행되면서, 공유 자원을 동시 접근하는 상황이 발생할 수 있다. 예를 들어, 여러 스레드가 동시에 하나의 변수에 접근하여 값을 변경하려고 할 때, 한 스레드가 작업을 완료하기 전에 다른 스레드가 그 변수에 접근하면 정확하지 않은 값이 나올 수 있다. 이를 방지하기 위해, 특정 스레드가 자원에 접근할 때 다른 스레드는 그 자원이 잠겨 있다는 것을 알 수 ..