Synchronization
This session is dedicated to the synchronization among threads / processesYou don't have to submit source files or reports for this sessions. For this session, you will need to log into a PC running Linux. If you are at Eurecom, simply log on a PC of rooms 52 or 53.
I. Why is synchronization necessary?
- Open the slides on Synchronization
- Watch the video on an introduction to synchronization
II. Implementing critical sections
- Open the slides on Synchronization, second section
- Watch the video on the implementation of critical sections
III. Programming with synchronization constraints
- Open the slides Synchronization, last section
- Watch the video on how to handle synchronization in code
- Have a look at the faulty code and try to understand why data can be equal to -1.
(Help me!)
The problem comes from the use of if. Actually, when a signal is sent on a condition variables, all waiting processes are awoken. So, for instance, two consumers could be awoken if data is equal to 2. The two awoken consumers will decrease data of, thus leading to data = -1. If the "if" is replaced with a "while", a process can only execute "data --" if data > 0