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 10:23:33 -0400 (EDT)
der Mouse <mouse%Rodents-Montreal.ORG@localhost> wrote:
> Maybe - but maybe not. Consider this partial (and, AFAIK,
> hypothetical) implementation:
>
> typedef struct {
> thread_list_t waiters;
> thread_list_t *waiters_tail;
> ...
> } pthread_mutex_t;
OK I see, it would work though if the lock object was a simple pointer.
I think it would be quite useful to be able to copy lock objects. As
you expand some data structures, you may need to expand the array
holding locks. If you have a large number of locks (e.g. hash table),
it's more efficient to call realloc() on the locks array and only
initialise new locks.
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.
Home |
Main Index |
Thread Index |
Old Index