Skip to content

Instantly share code, notes, and snippets.

View youngkaneda's full-sized avatar
🍂
無天

Juan Pablo youngkaneda

🍂
無天
  • Progress Rail Company
  • João Pessoa, PB, Brazil
View GitHub Profile
@youngkaneda
youngkaneda / Bakery.java
Last active July 26, 2020 04:06
Bakery algorithm for mutual exclusion.
// 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) {