Page 54 - Handout of Computer Architecture (1)..
P. 54
If they access shared data without coordination, the results may become incorrect.
Synchronization prevents this problem.
2.13.2. Shared Resources
A shared resource is anything used by more than one process.
Examples: Memory variables Files Printers Databases Buffers
Example Two programs update the same bank account balance.
Balance = 1000 Process A withdraws 100 Process B deposits 200
Without synchronization the final result may be wrong.
2.13.3. Critical Section
Every program has a part where it accesses shared data. This part is called the Critical Section.
Structure of a typical process:
Entry Section
Critical Section
Exit Section
Remainder Section
2.13.4 Explanation Entry Section
Process asks permission to enter the critical section. Critical Section Access shared resource.
Exit Section Release the resource. Remainder Section Normal code execution.
Important Rule: Only one process should execute the critical section at a time.
This rule is called Mutual Exclusion.
2.13.5. Race Condition
A Race Condition occurs when: Multiple processes try to modify shared data simultaneously.
Example: X = 10 Two processes want to execute: X = X + 1 Actual CPU operations are: 1 Read
X 2 Add 1 3 Write X
Possible execution:
54

