Re: Locks and threads

From:

Linas Vepstas

Subject:

Re: Locks and threads

Date:

Wed, 25 Mar 2009 17:34:03 -0500

2009/3/25 Neil Jerram <address@hidden>:
> Linas Vepstas <address@hidden> 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 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.
If there's no perf difference, then isn't that an argument
*for* rwlock, instead of against it?
> Also I would guess that we would hit more portability issues in future
> with a rwlock than with a mutex.
Well, since rwlock is a part of posix threads, wouldn't it
be available universally (wherever posix threads are
available)?
Are you voicing some suspicion that its somehow
buggier, or less tested?
(I have no direct experience on these two perf/portability
issues myself).
--linas