tech-userlevel archive

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

Re: Semantics of copying mutex/rwlock



> I mean, maybe it's conventional wisdom that you shouldn't make a copy
> of a mutex, but it seems logical to think that if you have a mutex
> and you know no threads are using it, then

> memcpy(&new_mutex, &old_mutex, sizeof(pthread_mutex_t))

> and having all threads use new mutex should be OK?

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;

with waiters_tail == &watiers if nobody is waiting on the mutex.  This
will fall over very hard if copied as you describe.

/~\ The ASCII                             Mouse
\ / Ribbon Campaign
 X  Against HTML                mouse%rodents-montreal.org@localhost
/ \ Email!           7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B


Home | Main Index | Thread Index | Old Index