Chapter 4 IPC New 2
Chapter 4 IPC New 2
Chapter 4:
Inter process communication(IPC)
• Inter process communication
• Race condition
• Critical section
• Mutual Exclusion
• Classic Problems
2
Inter process Communication
Semaphores
Shared memory
3
IPC- In distributed environment
Process B
Process A
time
request 1
response 1
request 2
interprocess communication
execution flow
response2
process blocked
m
m m m
P1 P1
unicast multicast
Socket communication Publish/Subscribe Message model,
7
Why we need to study-IPC
1. Disabling Interrupts
2. Lock Variable
3. Strict Alternation
4. Peterson’s algorithm
5. TSL instruction
14
Disabling Interrupts(Hardware Solution)
Each process disables all interrupts just after entering in its critical section
and re-enable all interrupts just before leaving critical section.
Has two drawbacks
Multi-processor
What if both processes claim to enter to their critical region almost simultaneously
Needs busy waiting, hence CPU time wastage is there.
20
TSL instruction
enter_region:
TSL REGISTER,LOCK |copy lock to register and set lock to 1
CMP REGISTER,#0 | was lock zero?
JNE enter_region | if it was non zero, lock was set, so loop
RET | return to caller; critical region entered
leave_region:
MOVE LOCK,#0 | store a 0 in lock
RET | return to caller
22
Sleep and Wakeup
Avoid priority inversion problem and CPU time wastage in TSL and
Peterson’s case.
Alternatively both sleep and wakeup use one parameter. A memory address that
much up both sleeps and wakeups.
23
Producer- Consumer problem
End of chapter 4