pthread_cond_wait requires that the mutex be at the same address in every process

Originator:tg
Number:rdar://19600706 Date Originated:26-Jan-2015 10:48 AM
Status:Open Resolved:
Product:OS X SDK Product Version:
Classification: Reproducible:Always
 
Summary:
_pthread_cond has a pointer to the mutex passed to pthread_cond_wait, and subsequent calls to pthread_cond_wait check that the mutex is at the same address. However, for mutexes constructed with PTHREAD_PROCESS_SHARED this check is incorrect, as you can have the same mutex at multiple addresses -- and when sharing a mutex between multiple processes, it normally will be at different addresses in each process. This means that in practice, condition variables can only reliably be shared between the parent and child of a fork().

Steps to Reproduce:
cc repro.c -o repro && ./repro && echo $?

Expected Results:
The program exits correctly and the return code of 0 is printed

Actual Results:
pthread_cond_wait on the second thread to reach it fails, resulting in an infinite loop.

Version:
Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
OS X 10.10.2 14C106a

Notes:
We're currently working around this by setting the `busy` field of `_pthread_cond` to NULL before calling pthread_cond_wait, which we can get away with since we don't cancel threads. This is of course highly fragile since it requires mucking about in a private data structure.

Configuration:
This has been a problem since pthread_condattr_setpshared was implemented.

Attachments:
'repro.c' was successfully uploaded.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!