The L-exclusion problem is a variant of the starvation-free mutual exclusion problem. We make two changes: as many as L threads may be in the critical section at the same time, and fewer than L threads might fail (by halting) in the critical section. An implementation must satisfy the following conditions:_____.
L-Exclusion: At any time, at most L threads are in the critical section.
L-Starvation-Freedom: As long as fewer than L threads are in the critical section, then some thread that wants to enter the critical section will eventually succeed (even if some threads in the critical section have halted).
Modify the n-process Bakery mutual exclusion algorithm to turn it into an L-exclusion algorithm. Do not consider atomic operations in your answer. You can provide a pseudo-code solution or written solution.

Respuesta :

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.