1. Homepage
  2. Exam
  3. [2021] CMPSC311 Introduction to Systems Programming - Q7 Prevent Race Condition

[2021] CMPSC311 Introduction to Systems Programming - Q7 Prevent Race Condition

This question has been solved
Engage in a Conversation

Question 7 CourseNana.COM

  CourseNana.COM

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. CourseNana.COM

  CourseNana.COM

1.    Describe one race condition CourseNana.COM

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. CourseNana.COM

  CourseNana.COM

#define MAX_SEAT 255 int num_of_people = 0; CourseNana.COM

  CourseNana.COM

int make_reservation() { CourseNana.COM

int id; CourseNana.COM

  CourseNana.COM

if (num_of_people == MAX_SEAT) { CourseNana.COM

id = -1; CourseNana.COM

} else { CourseNana.COM

++num_of_people; CourseNana.COM

id = register_user(); CourseNana.COM

} CourseNana.COM

  CourseNana.COM

return id; CourseNana.COM

} CourseNana.COM

  CourseNana.COM

void cancel_reservation(int id) { CourseNana.COM

if (is_valid_user(id)) { CourseNana.COM

--num_of_people; CourseNana.COM

deregister_user(id); CourseNana.COM

} CourseNana.COM

} CourseNana.COM

Get the Solution to This Question

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
Pennsylvania State University代写,PSU代写,Introduction to Systems Programming代写,CMPSC311代写,Pennsylvania State University代编,PSU代编,Introduction to Systems Programming代编,CMPSC311代编,Pennsylvania State University代考,PSU代考,Introduction to Systems Programming代考,CMPSC311代考,Pennsylvania State Universityhelp,PSUhelp,Introduction to Systems Programminghelp,CMPSC311help,Pennsylvania State University作业代写,PSU作业代写,Introduction to Systems Programming作业代写,CMPSC311作业代写,Pennsylvania State University编程代写,PSU编程代写,Introduction to Systems Programming编程代写,CMPSC311编程代写,Pennsylvania State Universityprogramming help,PSUprogramming help,Introduction to Systems Programmingprogramming help,CMPSC311programming help,Pennsylvania State Universityassignment help,PSUassignment help,Introduction to Systems Programmingassignment help,CMPSC311assignment help,Pennsylvania State Universitysolution,PSUsolution,Introduction to Systems Programmingsolution,CMPSC311solution,