12-06-2008
7,
0
Join Date: Sep 2008
Last Activity: 8 December 2008, 11:32 AM EST
Posts: 7
Thanks Given: 0
Thanked 0 Times in 0 Posts
pthread_rwlock_lock vs pthread_mutex_lock
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.