Answers
- There are many possible scenarios. Here is one:
- The first thread loses control after the first print statement.
- The second thread loses control just before the assignment balance = newBalance.
- The first thread completes the deposit method.
- The second thread completes the withdraw method.
- One thread calls addFirst and is preempted just before executing the assignment
first = newLink. Then the next thread calls addFirst, using the old value
of first. Then the first thread completes the process, setting first to its new
link. As a result, the links are not in sequence.