0

Can anyone give me the code example when i need to use Rlock instead of simple lock I am not able to find the use case when i need Rlock

I have read this but could not get the actual use of that

Normal Lock objects cannot be acquired more than once, even by the same thread. This can introduce undesirable side-effects if a lock is accessed by more than one function in the same call chain.

user192362127
  • 11,385
  • 8
  • 24
  • 21
  • [@User](http://stackoverflow.com/users/1320237/user) answered your question, you can take a look at this: [http://stackoverflow.com/a/16568426/5514109](http://stackoverflow.com/a/16568426/5514109) – Vuong Hoang Nov 04 '15 at 03:14

1 Answers1

0

It's mostly an issue for course grained locks (you do a lot of work while holding the lock). A thread will hang if it attempts to acquire a Lock more than once. The risk grows as a system gets complex and many functions acquire the lock. Suppose functions f1, f2, ... fn all acquire the lock. If f1 calls f2, it will hang. If f1 calls some other function and that function calls f2, it will hang. You end up implementing two sets of functions - ones that get the lock and ones that implement the functionality. "outies" and "innies". RLocks let you be more relaxed about that.

tdelaney
  • 73,364
  • 6
  • 83
  • 116