Question 7
Your city has an online vaccine reservation portal. Two functions make_reservation and cancel_reservation are shown below. Multiple users can simultaneously call the functions.
1. Describe one race condition
2. Assume you have a mutex lock named mutex with the operation mutex.acquire() and mutex.release(). Indicate where the locking needs to be placed to prevent all race conditions. You don't need to worry about performance.
#define MAX_SEAT 255 int num_of_people = 0;
int make_reservation() {
int id;
if (num_of_people == MAX_SEAT) {
id = -1;
} else {
++num_of_people;
id = register_user();
}
return id;
}
void cancel_reservation(int id) {
if (is_valid_user(id)) {
--num_of_people;
deregister_user(id);
}
}