Introduction (เคชเคฐเคฟเคเคฏ)
Operating System เคฎเฅเค เคเค processes เคฏเคพ threads เคเค เคธเคพเคฅ run เคเคฐเคคเฅ เคนเฅเคเฅค
เคเค เคฌเคพเคฐ เคฏเฅ processes เคเค เคนเฅ shared resource (เคเฅเคธเฅ variable, file, memory) เคเฅ access เคเคฐเคคเฅ เคนเฅเคเฅค
เค เคเคฐ เคเคจ processes เคเฅ properly control เคจเคนเฅเค เคเคฟเคฏเคพ เคเคฏเคพ, เคคเฅ system เคฎเฅเค error เคฏเคพ wrong output เค เคธเคเคคเคพ เคนเฅเฅค
เคเคธเฅ เคธเคฎเคธเฅเคฏเคพ เคเฅ Critical Section Problem เคเคนเคพ เคเคพเคคเคพ เคนเฅเฅค
Critical Section เคเฅเคฏเคพ เคนเฅเคคเคพ เคนเฅ
Program เคเคพ เคตเคน เคนเคฟเคธเฅเคธเคพ เคเคนเคพเค shared resource access เคเคฟเคฏเคพ เคเคพเคคเคพ เคนเฅ, เคเคธเฅ Critical Section เคเคนเคคเฅ เคนเฅเคเฅค
Simple Definition
Critical Section = code เคเคพ เคตเคน part เคเคนเคพเค shared data access เคนเฅเคคเคพ เคนเฅ
Critical Section Structure
เคนเคฐ process เคเฅ execution เคเฅ เคเคพเคฐ parts เคฎเฅเค divide เคเคฟเคฏเคพ เคเคพเคคเคพ เคนเฅ:

1. Entry Section
เคฏเคนเคพเค process check เคเคฐเคคเคพ เคนเฅ เคเคฟ เคตเคน critical section เคฎเฅเค enter เคเคฐ เคธเคเคคเคพ เคนเฅ เคฏเคพ เคจเคนเฅเคเฅค
2. Critical Section
เคฏเคน เคตเคน เคญเคพเค เคนเฅ เคเคนเคพเค shared resource use เคนเฅเคคเคพ เคนเฅเฅค
3. Exit Section
เคฏเคนเคพเค process critical section เคเฅเคกเคผเคคเคพ เคนเฅเฅค
4. Remainder Section
เคฌเคพเคเฅ normal code เคฏเคนเคพเค execute เคนเฅเคคเคพ เคนเฅเฅค
Race Condition เคเฅเคฏเคพ เคนเฅ
เคเคฌ เคฆเฅ เคฏเคพ เค เคงเคฟเค processes เคเค เคนเฅ เคธเคฎเคฏ เคชเคฐ shared data เคเฅ access เคเคฐเคคเฅ เคนเฅเค เคเคฐ result unpredictable เคฏเคพ เคเคฒเคค เคนเฅ เคเคพเคคเคพ เคนเฅ, เคเคธเฅ Race Condition เคเคนเคคเฅ เคนเฅเคเฅค
Example (เคธเคฎเคเคจเฅ เคเฅ เคฒเคฟเค)
เคฎเคพเคจ เคฒเฅ เคเค shared variable เคนเฅ:
count = 5
เคฆเฅ processes เคนเฅเค:
P1: count = count + 1
P2: count = count + 1
เค เคเคฐ เคฆเฅเคจเฅเค processes เคเค เคธเคพเคฅ execute เคเคฐเฅเค:
- เคฆเฅเคจเฅเค 5 read เคเคฐเฅเคเคเฅ
- เคฆเฅเคจเฅเค 6 write เคเคฐเฅเคเคเฅ
Final result = 6 (เคเคฒเคค)
Correct result = 7 (5+1+1) เคนเฅเคจเคพ เคเคพเคนเคฟเค
Critical Section Problem เคเคพ Goal
เคฏเคน ensure เคเคฐเคจเคพ เคเคฟ:
- เคเค เคธเคฎเคฏ เคฎเฅเค เคเฅเคตเคฒ เคเค process critical section เคฎเฅเค เคเคพเค
- data corruption เคจ เคนเฅ
- correct output เคฎเคฟเคฒเฅ
Solution Requirements
Critical Section Problem เคเคพ เคธเคนเฅ solution เคเคจ เคคเฅเคจ conditions เคเฅ satisfy เคเคฐเคจเคพ เคเคพเคนเคฟเค:
1. Mutual Exclusion
เคเค เคธเคฎเคฏ เคฎเฅเค เคเฅเคตเคฒ เคเค process critical section เคฎเฅเค เคนเฅเคจเคพ เคเคพเคนเคฟเคเฅค
2. Progress
เค เคเคฐ critical section เคเคพเคฒเฅ เคนเฅ, เคคเฅ เคเคฟเคธเฅ waiting process เคเฅ enter เคเคฐเคจเฅ เคฆเคฟเคฏเคพ เคเคพเคจเคพ เคเคพเคนเคฟเคเฅค
3. Bounded Waiting
เคนเคฐ process เคเฅ limited time เคฎเฅเค chance เคฎเคฟเคฒเคจเคพ เคเคพเคนเคฟเคเฅค
เคเฅเค process indefinite wait เคจ เคเคฐเฅเฅค
Real Life Example
เคฎเคพเคจ เคฒเฅ เคเค bank account เคนเฅ:
- Balance = 1000
- เคฆเฅ เคฒเฅเค เคเค เคธเคพเคฅ เคชเฅเคธเฅ เคจเคฟเคเคพเคฒ เคฐเคนเฅ เคนเฅเค
เค เคเคฐ system properly control เคจเคนเฅเค เคเคฐเคคเคพ:
- เคฆเฅเคจเฅเค same balance เคฆเฅเคเฅเคเคเฅ
- เคฆเฅเคจเฅเค เคชเฅเคธเฅ เคจเคฟเคเคพเคฒ เคฒเฅเคเคเฅ
Result: เคเคฒเคค balance
Solution Techniques (Short Idea)
Critical Section Problem เคเฅ solve เคเคฐเคจเฅ เคเฅ เคฒเคฟเค:
- Locks
- Semaphores
- Monitors
เคเคพ use เคเคฟเคฏเคพ เคเคพเคคเคพ เคนเฅ (เคเคจ topics เคเฅ เคเคเฅ เคชเคขเคผเฅเคเคเฅ)
Key Points (Exam Focus)
- Critical Section definition
- Race Condition example
- Mutual Exclusion, Progress, Bounded Waiting
- Structure (Entry, Critical, Exit, Remainder)
Conclusion
Critical Section Problem Operating System เคเคพ เคเค fundamental concept เคนเฅ, เคเฅ shared resources เคเฅ safe use เคเฅ ensure เคเคฐเคคเคพ เคนเฅเฅค
เค เคเคฐ เคเคธเฅ เคธเคนเฅ เคคเคฐเฅเคเฅ เคธเฅ handle เคจเคนเฅเค เคเคฟเคฏเคพ เคเคพเค, เคคเฅ system เคฎเฅเค เคเคฒเคค data เคเคฐ inconsistent results เค เคธเคเคคเฅ เคนเฅเคเฅค