Question: public boolean add(T item) { int key = item.hashCode(); while (true) { Node pred = head; Node curr = pred.next; while (curr.key
public boolean add(T item) { int key = item.hashCode();
while (true) {
Node pred = head; Node curr = pred.next;
while (curr.key <= key) {
pred = curr; curr = curr.next; pred.lock(); curr.lock(); try { if (validate(pred, curr)) { if (curr.key == key) {return false; } else { Node node = new Node(item); node.next = curr;
pred.next = node; return true;
} }
} finally { pred.unlock(); curr.unlock();
} } } }
Show that in the optimistic algorithm, the add() method needs to only lock pred.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
