I am thinking of using non-recursive locks; I have found them to be having performance superiority over the standard recursive locks (e.g. SimpleRWSync). I have mainly been using critical sections but in highly threaded environments, locking was producing significant delays.

  1. What are the benefits and/or pitfalls?
  2. Do the non-recursive ones make coding harder comparatively?

1 Answer 1


The benefit of non-recursive locks is they are faster, because of reduced tracking and checking for which thread is holding the lock. The drawback is you will deadlock if you try to lock it again within the same thread.

Technically, they are harder to use, because the burden is on the programmer to avoid locking it recursively. In practice, programmers should already be worrying about it. Most of the time, holding a lock recursively means you are holding it too long. You want the time you are holding a lock to be as small as possible, and making function calls of unknown depth can hardly be considered as small as possible. It may be a little bit of extra work, but refactoring your code to be able to use non-recursive locks is almost always worth it.

  • From the production point of view, should such be considered early in the development phase or in the post-release optimization phase? Feb 13, 2014 at 9:13
  • It's just best practices. If you follow them early, you won't need an optimization phase. Feb 13, 2014 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.