> For the complete documentation index, see [llms.txt](https://krjaeh0.gitbook.io/j-log/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://krjaeh0.gitbook.io/j-log/programming/cs_basics/os_memory/concurrency-and-synchronization/mutualexclusion.md).

# MutualExclusion

## 상호 배제(Mutual Exclusion)란?

* 두 개 이상의 프로세스(또는 스레드)가 동시에 하나의 임계 구역(Critical Section)에 들어가는 것을 방지하는 원칙
* 한 번에 오직 하나의 프로세스만 공유 자원(메모리, 파일, 디바이스 등)을 사용하게 하는 것을 의미
* 동시 접근으로 인한 데이터 손상, 예측 불가능한 결과, 보안 문제, 시스템 오류 등을 방지한다.

## 상호 배제 조건

{% stepper %}
{% step %}

### 단일 접근 보장

임계 구역에는 오직 하나의 프로세스만 들어갈 수 있다.
{% endstep %}

{% step %}

### 비간섭성

임계 구역 외부의 프로세스는 내부에서 일어나는 일에 간섭하지 않는다.
{% endstep %}

{% step %}

### 공정성

모든 프로세스가 임계 구역에 들어갈 기회를 공평하게 가져야 한다.
{% endstep %}

{% step %}

### 진행성

어떤 프로세스도 영원히 차단되어 임계 구역을 할당받지 못하면 안 된다.
{% endstep %}
{% endstepper %}

## 상호 배제의 주의사항

{% stepper %}
{% step %}

### 데드락 (Deadlock)

둘 다 자원 확보를 기다리는 상태.
{% endstep %}

{% step %}

### 기아 상태 (Starvation)

특정 프로세스가 자원을 계속 얻지 못하는 상태.
{% endstep %}

{% step %}

### Busy Waiting

CPU를 낭비하는 대기 방식.
{% endstep %}
{% endstepper %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://krjaeh0.gitbook.io/j-log/programming/cs_basics/os_memory/concurrency-and-synchronization/mutualexclusion.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
