Bloomberg LP Interview Question
Financial Software DevelopersSuppose you have 2 threads and infinite history of executions of instructions of 1 and 2 thread. In both threads there is a critical section. Consider the following algorithm:
loop forever
NCS()
want[id] <- 1
loop while (want[1 - id] == 1)
CS()
want[id] <- 0
end loop
// id is either 0 or 1
If there exists a possibility that this algorithm will never enter a critical section of any thread then it is in deadlock. It doesn't seem for the above algo that it may be in the deadlock but indeed it is possible :) It up to you to find why...
deadlock is where transaction A is waiting for transaction B; and transaction B is waiting on transaction A.
- Anonymous January 02, 2009