From: Yaakov Selkowitz <yselkowitz@cygwin.com>
To: cygwin-patches@cygwin.com
Subject: [PATCH] default to normal pthread mutexes
Date: Sun, 13 Jul 2014 23:38:00 -0000 [thread overview]
Message-ID: <53C31871.9020900@cygwin.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 283 bytes --]
Defaulting to ERRORCHECK mutexes (with the various stringencies it
implies) does not match the behaviour on Linux, where NORMAL mutexes are
the default. I have been testing this locally for some time, and I
believe it affects a lot of software. Patch and STC attached.
Yaakov
[-- Attachment #2: pthread-mutex-default.patch --]
[-- Type: text/plain, Size: 2388 bytes --]
2014-07-13 Yaakov Selkowitz <yselkowitz@...>
* thread.cc (pthread_mutex::pthread_mutex): Change default type
to PTHREAD_MUTEX_NORMAL.
(pthread_mutexattr::pthread_mutexattr): Ditto.
(pthread_mutex_unlock): Do not fail if mutex is a normal mutex
initializer.
* include/pthread.h (PTHREAD_MUTEX_INITIALIZER): Redefine as
PTHREAD_NORMAL_MUTEX_INITIALIZER_NP.
Index: thread.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/thread.cc,v
retrieving revision 1.287
diff -u -p -r1.287 thread.cc
--- thread.cc 1 Dec 2013 10:27:16 -0000 1.287
+++ thread.cc 26 Mar 2014 04:24:08 -0000
@@ -1708,7 +1708,7 @@ pthread_mutex::pthread_mutex (pthread_mu
tid (0),
#endif
recursion_counter (0), condwaits (0),
- type (PTHREAD_MUTEX_ERRORCHECK),
+ type (PTHREAD_MUTEX_NORMAL),
pshared (PTHREAD_PROCESS_PRIVATE)
{
win32_obj_id = ::CreateEvent (&sec_none_nih, false, false, NULL);
@@ -1850,7 +1850,7 @@ pthread_mutex::_fixup_after_fork ()
}
pthread_mutexattr::pthread_mutexattr ():verifyable_object (PTHREAD_MUTEXATTR_MAGIC),
-pshared (PTHREAD_PROCESS_PRIVATE), mutextype (PTHREAD_MUTEX_ERRORCHECK)
+pshared (PTHREAD_PROCESS_PRIVATE), mutextype (PTHREAD_MUTEX_NORMAL)
{
}
@@ -3158,7 +3158,7 @@ extern "C" int
pthread_mutex_unlock (pthread_mutex_t *mutex)
{
if (pthread_mutex::is_initializer (mutex))
- return EPERM;
+ pthread_mutex::init (mutex, NULL, *mutex);
if (!pthread_mutex::is_good_object (mutex))
return EINVAL;
return (*mutex)->unlock ();
Index: include/pthread.h
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/include/pthread.h,v
retrieving revision 1.39
diff -u -p -r1.39 pthread.h
--- include/pthread.h 26 Feb 2013 10:32:36 -0000 1.39
+++ include/pthread.h 26 Mar 2014 04:24:08 -0000
@@ -49,7 +49,7 @@ extern "C"
#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP (pthread_mutex_t)18
#define PTHREAD_NORMAL_MUTEX_INITIALIZER_NP (pthread_mutex_t)19
#define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP (pthread_mutex_t)20
-#define PTHREAD_MUTEX_INITIALIZER PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
+#define PTHREAD_MUTEX_INITIALIZER PTHREAD_NORMAL_MUTEX_INITIALIZER_NP
#define PTHREAD_ONCE_INIT { PTHREAD_MUTEX_INITIALIZER, 0 }
#if defined(_POSIX_THREAD_PRIO_INHERIT) && _POSIX_THREAD_PRIO_INHERIT >= 0
#define PTHREAD_PRIO_NONE 0
[-- Attachment #3: pthread-mutex-test.c --]
[-- Type: text/plain, Size: 1008 bytes --]
#include <pthread.h>
#include <stdio.h>
#include <error.h>
int
main(void)
{
int ret;
pthread_mutexattr_t attr;
pthread_mutex_t mutex;
#ifdef __CYGWIN__
pthread_mutex_t mutexstatic = PTHREAD_NORMAL_MUTEX_INITIALIZER_NP;
#else
pthread_mutex_t mutexstatic = PTHREAD_MUTEX_INITIALIZER;
#endif
pthread_mutexattr_init(&attr);
{
int type;
printf ("PTHREAD_MUTEX_NORMAL = %d\n", PTHREAD_MUTEX_NORMAL);
printf ("PTHREAD_MUTEX_ERRORCHECK = %d\n", PTHREAD_MUTEX_ERRORCHECK);
printf ("PTHREAD_MUTEX_DEFAULT = %d\n", PTHREAD_MUTEX_DEFAULT);
pthread_mutexattr_gettype (&attr, &type);
printf ("pthread_mutexattr_init(NULL) type is: %d\n", type);
}
pthread_mutex_init(&mutex, &attr);
pthread_mutexattr_destroy(&attr);
if ((ret = pthread_mutex_unlock(&mutex)))
error(0, ret, "pthread_mutex_unlock(mutex)");
// pthread_mutex_init(&mutexstatic, NULL);
if ((ret = pthread_mutex_unlock(&mutexstatic)))
error(0, ret, "pthread_mutex_unlock(mutexstatic)");
return 0;
}
next reply other threads:[~2014-07-13 23:38 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-13 23:38 Yaakov Selkowitz [this message]
2014-07-14 9:45 ` Corinna Vinschen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=53C31871.9020900@cygwin.com \
--to=yselkowitz@cygwin.com \
--cc=cygwin-patches@cygwin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).