Previous | Next --- Slide 31 of 66
Back to Lecture Thumbnails
anamdev

The deadlock in this situation occurs because the two threads are trying to lock both A and B before performing any of the functions. Wouldn't a simple fix (in this situation) be to this be to call withdraw or deposit only within 2 single (rather than nested) synchronization blocks? Are there downsides to this in terms of performance? I do see the value of TM, but I am curious about the example provided in this slide.

MangoSister

I think the point here to show that manually write lock-based code is not trivial in many cases. Although I agree that it is easy to fix this example, but the problem may get much more complicated in some other cases, where using TM will make your life much easier.