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;

}

}

  1. 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.

  1. Add a transfer function, which transfer parcels from one box to another that is thread safe.

  1. Give a lock-free thread safe version of Parcel_Delivery.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!