This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// pid goes from 0 to THREAD_POOL_SIZE - 1 | |
public class Bakery { | |
private static int THREAD_POOL_SIZE = 10; | |
private volatile static boolean[] guests = new boolean[THREAD_POOL_SIZE]; | |
private volatile static int[] tickets = new int[THREAD_POOL_SIZE]; | |
public void lock(int pid) { | |
guests[pid] = true; | |
synchronized (tickets) { |