I have been wondering what the difference between pthread_rwlock_lock and pthread_mutex_lock is. Both these routines acquire an exclusive rw lock on an enclosed region.
So I performed a simple experiment in which I execute both these routines multiple times in a loop. Here are the results:
Time taken for 8388608 loops of rwlock = 1.077198 sec
Time taken for 8388608 loops of mutex_lock = 0.337276 sec
As you can see, mutex locking is much faster than the rwlock_lock. Then when would one prefer to use pthread_rwlock_lock over a mutex lock ??
Thanks for your help.