Locking Guidelines
In my last post ( Lock Up Unlocked ), I gave you some basic guidelines for locking resources in multi-threaded programs. Basic guidelines for locking. Avoid simultaneously locking multiple shared resources in a single thread. If multiple shared resources must be locked simultaneously, endeavor that all threads lock the resources in the same order and unlock them in reverse order. If they can't be unlocked in reverse order, then endeavor to unlock in the same order and do not lock an earlier resource till all later locks are released. If you can't follow these guidelines, then timeout. In today's post, I am going to elaborate a little on each principle. But first, let's discuss "resources". Many of you can quickly name the commonly understood resources. Things like memory, cpu, network jump right out, but that's because we are so used to looking at Task Manager and Resource Monitor. Besides, they are a little esoteric, programmers are concerned about sp...