| 36 | } |
| 37 | |
| 38 | public boolean hasCycle(Hashtable<Integer, Boolean> touchedNodes, int[] resourcesInOrder) { |
| 39 | /* check for a cycle */ |
| 40 | for (int resource : resourcesInOrder) { |
| 41 | if (touchedNodes.get(resource) == false) { |
| 42 | LockNode n = locks[resource]; |
| 43 | if (n.hasCycle(touchedNodes)) { |
| 44 | return true; |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | /* To prevent deadlocks, force the processes to declare upfront what order they will |
| 52 | * need the locks in. Verify that this order does not create a deadlock (a cycle in a directed graph) |