Hi, I'm trying to track down the source of a particular piece of coding advice I once read. I'm currently working with a class that has a lot of threading around a single shared resource, controlled by a mutex. I just spent a week trying to debug the damn code, because it's difficult to spot sub-functions which don't self-lock, and one was writing during a read. Occasionally. Under a near impossible to predict set of circumstances.
I never want to deal with this again, and I think I've devised a guideline which should reduce this kind of faff in the future, which is to rename all functions that access the resource, adding a suffix:
- "NeedsLock": Accesses the resource but doesn't lock. (i.e. This function must be run inside a lock).
- "Locks": Locks and accesses the resource (i.e. This function must NOT be run inside a lock)
The problem is that I know I've read this advice somewhere, and when I have to back up my decision (because Hungarian Notation? What is this, the 60's?), I'd like to be able to point to the source. I also want to check that I'm not missing anything important from the original idea.
Does this style seem familiar to anyone?