1 36 package org.columba.ristretto.concurrency; 37 38 43 public class Mutex { 44 private boolean mutex; 45 46 50 public Mutex() { 51 mutex = false; 52 } 53 54 60 public synchronized void lock() { 61 while (mutex) { 62 try { 63 wait(); 65 } catch (InterruptedException e) { 66 if (Thread.currentThread().isInterrupted()) { 67 throw new RuntimeException (e); 69 } 70 } 72 } 73 mutex = true; 74 } 75 76 81 public synchronized void release() { 82 mutex = false; 83 84 notify(); 85 } 86 } 87 | Popular Tags |