I was asked this question in an .net / C # interview:
If we have two streams T1 and T2. T1 gets a lock on obj1, and then does some processing and gets a lock on obj2. T2 gets a lock on obj2 and then processes and acquires a lock on obj1. So we can dead end. What is the usual technique that we use in multithreading to avoid this situation?
I replied by saying that T1 and T2 should have some mechanism for communication, and we should do the coding so that T2 starts to do its work only after T1 signals that it is doing with its work. The interviewer asked me if I knew about transactions and how we can use it to meet this deadlock. I have a lot of user-side threading experience in winforms. But I have never used transactions. Can someone tell me more about this or point me to url / book,
source
share