tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Semantics of copying mutex/rwlock



On Wed, 16 Jun 2010 16:48:16 +0100
Sad Clouds <cryintothebluesky%googlemail.com@localhost> wrote:

> On Wed, 16 Jun 2010 11:27:48 -0400 (EDT)
> der Mouse <mouse%Rodents-Montreal.ORG@localhost> wrote:
> 
> > > What I do is call pthread_mutex_destroy() on every old lock,
> > > allocate a new array, call pthread_mutex_init() on all locks in
> > > new array and then free old array.  I guess there is no way
> > > around it.
> > 
> > There is, actually - you could use an array of pthread_mutex_t *,
> > with the mutexes themselves allocated separately and individually.
> > It means more allocations and complicated allocation code, it might
> > be worth it.
> 
> Yeah it's a good idea, this is what I do with hash table buckets, it's
> just a pointer to linked list. I definitely need to run a benchmark to
> see if malloc()/*init() for each new lock is faster.

OK I wrote a simple benchmark. It turns out malloc() is quite
expensive, it's about 6 times slower to call malloc() for each mutex,
compared to init/destroy pair.


Home | Main Index | Thread Index | Old Index