Go to Google Groups Home    comp.unix.programmer
Re: copying pthread_mutex_t, pthread_cond_t

David Schwartz <dav...@webmaster.com>

On Jul 4, 2:50 am, James Kanze <james.ka...@gmail.com> wrote:

> Basically, is it legal to copy a pthread_mutex_t or a
> pthread_cond_t, and use the copy?

No. The reason is simple -- that is semantically ambiguous. Does the
copy refer to the mutex, simply copying the reference to it? Or does
it refer to a new mutex initialized to the same state as the original
mutex? If the mutex copied is locked, is the copy locked?

> If not (which is the only
> answer which makes sense to me), where does the Posix
> specification say this?

Where does the POSIX specification say you can't add one to a
pthread_mutex_t? The standard does not have to explicitly prohibit
every crazy thing you can imagine to do.

> If so, what does it mean: what happens,
> for example, if a copy a mutex which is held by a thread, wait
> on the copy, and the holding thread frees the original?

The standard doesn't say. So, anything can happen. (Or, if it does, I
couldn't find where.)

DS