possible pthread_mutex_init bug: reads uninitialized memory
Frederic Devernay
Frederic.Devernay@sophia.inria.fr
Thu Aug 30 00:46:00 GMT 2001
Hello,
there are officially two ways to initialize a pthread mutex:
pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
or
pthread_mutex_t mut;
pthread_mutex_init(&mut,NULL);
the problem is that the pthread_mutex_init in cygwin reads the of-course
uninitialized memory:
as seen in cygwin-1.3.2-1/winsup/cygwin/thread.cc:
__pthread_mutex_init (pthread_mutex_t * mutex,
const pthread_mutexattr_t * attr)
{
if ((((pshared_mutex *)(mutex))->flags & SYS_BASE == SYS_BASE))
// a pshared mutex
return EBUSY;
...
If found this bug not by declaring a local variable as above, but by allocating
the mutex. the only workaround I found was to memset the memory area before
calling pthread_mutex_init.
I don't know what a pshared_mutex is, but pthread_mutex_init should really
not assume that anything is valid in the given mutex!
Fred
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
More information about the Cygwin
mailing list