Jerry Feldman wrote:
On 02/11/2010 04:35 AM, Per Jessen wrote:
What's the difference between pthread_rwlock_wrlock and pthread_mutex_lock? I understand the difference if we take pthread_rwlock_rdlock into account, but is there any difference between using purely pthread_rwlock_wrlock() vs. pthread_mutex_lock() ?
Let me try to answer this since I've implemented this type of thing before. The pthread_mutex_lock is a general purpose lock object. The locking thread causes all other threads that use that mutex to block. Very simple. The pthread_rwlock_wrlock() and its sibling pthread_rwlock_rdlock() implement a reader-writer strategy there are many readers and a few writers. The basic issue is that you want to allow reader threads to proceed, but you want to block writers. If a writer thread calls pthread_rwlock_wrlock(), it will block if a reader thread has called the rdlock, but it will also block subsequent readers. So basically, in your question, if you only use wrlock() then the effect is the same as the standard mutex lock, but it appears there is more overhead associated with it.
Thanks, that is what I thought too, but I was getting results inconsistent with that. I was just wondering if my understanding was flawed :-) /Per Jessen, Zürich -- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-programming+help@opensuse.org