When would you ever use nested locking?

前端 未结 3 1023
轮回少年
轮回少年 2021-01-07 23:22

I was reading in Albahari\'s excellent eBook on threading and came across the following scenario he mentions that \"a thread can repeatedly lock the same object in a nested

3条回答
  •  独厮守ぢ
    2021-01-07 23:38

    If you have a resource that you want exclusive control over, but many methods act upon this resource. A method might not be able to assume that it is locked so it will lock it within it's method. If it's locked in the outer method AND inner method, then it provides a situation similar to the example in the book. I cannot see a time where I would want to lock twice in the same code block.

提交回复
热议问题