Linas Vepstas <linasveps...@gmail.com> writes: > Well, once you identify the section that needs locking, > you'll want to use an rwlock instead of a mutex. The > rwlock (pthread_rwlock_rdlock) allows multiple > simultaneous readers. The writers, however, get > exclusive access. (pthread_rwlock_wrlock)
I forgot to comment on this before... In my view the important case to optimize is the one with only a single thread - i.e. I don't want to add any significant performance penalty in that case. And for that case, IIUC, there is no difference between a mutex and an rwlock. Also I would guess that we would hit more portability issues in future with a rwlock than with a mutex. Of course, we could look at configure time for rwlock support, and fall back to a mutex - but that has a cost too, in code complexity. On balance, therefore, I don't think using a rwlock rather than a mutex is worthwhile. Regards, Neil