Question: Concurrent and Parallel Programming Given the following java class called Parcel_Delivery, class Parcel_Delivery { private int[] b; public Parcel_Delivery(int n) { b = new int[n];
Concurrent and Parallel Programming
Given the following java class called Parcel_Delivery,
class Parcel_Delivery {
private int[] b;
public Parcel_Delivery(int n) {
b = new int[n];
for (int i = 0; i < n; i++) {
b[i] = 0;
}
}
public void deliver(int i, int parcels) {
b[i] = b[i] + parcels;
}
public int empty(int i) {
int result = b[i];
box = 0;
return result;
}
}
- Make a thread safe version of class Parcel_Delivery in such a way that delivery deliver parcels at same time and do not block each other.
- Add a transfer function, which transfer parcels from one box to another that is thread safe.
- Give a lock-free thread safe version of Parcel_Delivery.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
