https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=9409c5335bfac54ccd89fbe931e670b797462e05
commit 9409c5335bfac54ccd89fbe931e670b797462e05 Author: Corinna Vinschen <[email protected]> Date: Wed Apr 20 12:31:45 2016 +0200 Don't test pthread objects for being already initialized at init time For all pthread init functions, POSIX says Results are undefined if pthread_FOO_init() is called specifying an already initialized pthread_FOO object. So far our pthread init functions tested the incoming object if it's already an initialized object and, if so, returned EBUSY. That's ok *iff* the object was already initialized. However, as the example in https://cygwin.com/ml/cygwin/2016-04/msg00473.html shows, an uninitialized pthread object could also accidentally look like an initialized object and then returning EBUSY is not ok. Consequentially, all those tests are dangerous. Per POSIX, an application has to know what its doing when calling any of the pthread init functions anyway, and re-initializing the object is just as well as undefined behaviour as is returning EBUSY on already initialized objects. * thread.cc (pthread_attr_init): Drop check for already initialized object. (pthread_condattr_init): Ditto. (pthread_rwlockattr_init): Ditto. (pthread_mutexattr_init): Ditto. Signed-off-by: Corinna Vinschen <[email protected]> Diff: --- winsup/cygwin/thread.cc | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc index 05757ac..ec59f1f 100644 --- a/winsup/cygwin/thread.cc +++ b/winsup/cygwin/thread.cc @@ -2175,9 +2175,6 @@ pthread::atfork (void (*prepare)(void), void (*parent)(void), void (*child)(void extern "C" int pthread_attr_init (pthread_attr_t *attr) { - if (pthread_attr::is_good_object (attr)) - return EBUSY; - *attr = new pthread_attr; if (!pthread_attr::is_good_object (attr)) { @@ -2854,9 +2851,6 @@ pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex) extern "C" int pthread_condattr_init (pthread_condattr_t *condattr) { - if (pthread_condattr::is_good_object (condattr)) - return EBUSY; - *condattr = new pthread_condattr; if (!pthread_condattr::is_good_object (condattr)) { @@ -3040,9 +3034,6 @@ pthread_rwlock_unlock (pthread_rwlock_t *rwlock) extern "C" int pthread_rwlockattr_init (pthread_rwlockattr_t *rwlockattr) { - if (pthread_rwlockattr::is_good_object (rwlockattr)) - return EBUSY; - *rwlockattr = new pthread_rwlockattr; if (!pthread_rwlockattr::is_good_object (rwlockattr)) { @@ -3370,9 +3361,6 @@ pthread_mutexattr_gettype (const pthread_mutexattr_t *attr, int *type) extern "C" int pthread_mutexattr_init (pthread_mutexattr_t *attr) { - if (pthread_mutexattr::is_good_object (attr)) - return EBUSY; - *attr = new pthread_mutexattr (); if (!pthread_mutexattr::is_good_object (attr)) {
