...Concurrency (contd.)
P1 invokes echo, after it inputs into in , gets interrupted (switched). P2 invokes echo, inputs into in and completes the execution and exits. When P1 returns in is overwritten and gone. Result: first ch is lost and second ch is written twice.
This type of situation is even more probable in multiprocessing systems where real concurrency is realizable thru’ multiple processes executing on multiple processors.
Solution: Controlled access to shared resource
- Protect the shared resource : in buffer; “critical resource”
- one process/shared code. “critical region”