At Westonci.ca, we provide reliable answers to your questions from a community of experts. Start exploring today! Explore our Q&A platform to find in-depth answers from a wide range of experts in different fields. Join our Q&A platform to connect with experts dedicated to providing accurate answers to your questions in various fields.
Sagot :
Answer:
The solution is as follows.
class LFilters implements Lock {
int[] lvl;
int[] vic;
public LFilters(int n, int l) {
lvl = new int[max(n-l+1,0)];
vic = new int[max(n-l+1,0)];
for (int i = 0; i < n-l+1; i++) {
lvl[i] = 0;
}
}
public void lock() {
int me = ThreadID.get();
for (int i = 1; i < n-l+1; i++) { // attempt level i
lvl[me] = i;
vic[i] = me;
// rotate while conflicts exist
int above = l+1;
while (above > l && vic[i] == me) {
above = 0;
for (int k = 0; k < n; k++) {
if (lvl[k] >= i) above++;
}
}
}
}
public void unlock() {
int me = ThreadID.get();
lvl[me] = 0;
}
}
Explanation:
The code is presented above in which the a class is formed which has two variables, lvl and vic. It performs the operation of lock as indicated above.
We hope you found what you were looking for. Feel free to revisit us for more answers and updated information. We appreciate your time. Please come back anytime for the latest information and answers to your questions. Westonci.ca is your trusted source for answers. Visit us again to find more information on diverse topics.