Subj : Re: performance of single mutex versus Read/write mutex: any numbers? To : comp.programming.threads From : Joe Seigh Date : Thu Oct 06 2005 08:23 am Mike Winter wrote: > If I have a small critical section to access an element of a structure > (queue) and most accesses are reads and once in a blue moon a write (PI > seconds is a nano-century!) occurs where the primary element is superceded, > but only completely superceded when its reference count is 0(no more > readers), I think a single mutex may be overkill. I would think that a > single mutex would be less performant than say a more complex structure like > say a read-write mutex. Then I think about what it takes to manage a > ReadWriteMutex (mutex + reader-count + writing). > > Consider > > struct ReadWriteMutex { > Mutex mWriterMutex; // gets grabbed rarely > AtomicCounter mReaderCount; // gets incremented/decremented securely > and fast > ReaderMutex mReaderMutex; // only blocks if mWriterMutex is locked > }; > > Thats the context/concept. > > Heres the question: Are there any numbers /papers in the ether that can > point to how the ReaderWriterMutex will compare to the ordinary Mutex? Links > welcomed > It's not clear what's being synchronized here. The queue or the elements on the queue? The solution would depend on what you're doing. rwlocks are part of Posix so you're better off using them if they're implemented than implementing your own if you don't have any experience there. Also rwlocks are a limited scalability solution and only really work well in certain situations, otherwise you're better off not using them, though they are useful as documenting read vs. write shared access. Reference counting comes periously close to lock-free. You probably want to avoid that if you aren't experienced encough to deal with the wailing, gnashing of ones teeth, and rending of ones garments when that term is mentioned, though it does make for great entertainment. I'm sure though that once you explain your situation a little better, the wailers will be happy to show you how to get back on the One True Path. -- Joe Seigh When you get lemons, you make lemonade. When you get hardware, you make software. .