Question: You are asked to build a system that controls a bicycle sharing systems. Bicycles are loaned out freely to any customers that show up to
You are asked to build a system that controls a bicycle sharing systems. Bicycles are loaned out freely to any customers that show up to ask for them, but it's essential to track who has which bicycle. Your customers may represent groups of people, so when they show up, they ask for a number of bicycles.
You do not have an infinite supply of bicycles, so you should assume you have an array "int bicycleArray[N]" that is used to track which customer has which bicycle(s). Every array element represents an individual bicycle, and the value of that element indicates the customer ID of the customer who has the bicycle. Customers have positive integer IDs, so you may use "0" to represent a bicycle that has not been loaned out.
Please provide the pseudocode for how you would imagine a customer thread. Customer "i" who shows up asking for a total of "j" bicycles, is to be represented by a function "Customer(i,j)" that should clearly show how the array is updated at the start. You need to show how a customer thread will safely claim the desired number of bicycles, You do NOT need to show detailed pseudocode for how bicycles are returned (that can be left as a comment if that's easier, but the code for how the bicycles are taken is important to show in detail. You may assume any synchronization primitive that you wish, but clearly indicate any assumptions you make.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
