123456789101112131415161718192021222324252627 |
- public abstract class Mutex {
- public static void criticalSection() {
- try {
- Thread.sleep((int) (Math.random() * 3000));
- }
- catch (InterruptedException e) {
- // Nothing
- }
- }
- public static void nonCriticalSection() {
- try {
- Thread.sleep((int) (Math.random() * 3000));
- }
- catch (InterruptedException e) {
- // Nothing
- }
- }
- // Take ownership
- public abstract void p(int id);
- // Release ownership
- public abstract void v(int id);
- }
|