Previous | Next --- Slide 32 of 65
Back to Lecture Thumbnails
ask

The problem illustrated here is similar to a potential deadlock scenario in the concurrent hashmap implementation in exercise 4. An imperative approach to fixing this problem would be acquiring locks in the increasing order of account numbers. However, this is additional logic that the developer will have to foresee and add to code in order to ensure the desired behavior and make it deadlock free. However, using a declarative approach of using atomic makes development simpler and the developer will not need to add any additional logic to make this deadlock free.

pdp

If different programmers are developing different modules of the system and one writes transfer and the other writes transfer2, the system would have a deadlock and hence lock-based schemes require system-wide policies amidst all the developers to avoid incorrect programs.

1_1

One way to fix this problem is to have one thread abort after waiting a certain amount of time for the lock. We could also maintain some notion of priority among threads to decide which thread should abort. This would mean we would need another thread constantly checking if a deadlock is occurring.