Thread (57 messages) flat view 57 messages, 7 authors, 2016-10-27

Re: [PATCH 27/36] attr: convert to new threadsafe API

From: Johannes Schindelin <hidden>
Date: 2016-10-26 08:52:44
Subsystem: the rest · Maintainer: Linus Torvalds

Hi Stefan,

On Sat, 22 Oct 2016, Stefan Beller wrote:
quoted hunk ↗ jump to hunk
@@ -46,6 +47,19 @@ struct git_attr {
 static int attr_nr;
 static struct git_attr *(git_attr_hash[HASHSIZE]);
 
+#ifndef NO_PTHREADS
+
+static pthread_mutex_t attr_mutex;
+#define attr_lock()		pthread_mutex_lock(&attr_mutex)
+#define attr_unlock()		pthread_mutex_unlock(&attr_mutex)
This mutex is never initialized. That may work on the system you tested,
but it is incorrect, and it does segfault on Windows. A lot.

I need *at least* something like this to make it stop crashing all over
the test suite:

-- snipsnap --
diff --git a/attr.c b/attr.c
index d5a6aa9..6933504 100644
--- a/attr.c
+++ b/attr.c
@@ -50,7 +50,16 @@ static struct git_attr *(git_attr_hash[HASHSIZE]);
 #ifndef NO_PTHREADS
 
 static pthread_mutex_t attr_mutex;
-#define attr_lock()pthread_mutex_lock(&attr_mutex)
+static inline void attr_lock(void)
+{
+	static int initialized;
+
+	if (!initialized) {
+		pthread_mutex_init(&attr_mutex, NULL);
+		initialized = 1;
+	}
+	pthread_mutex_lock(&attr_mutex);
+}
 #define attr_unlock()pthread_mutex_unlock(&attr_mutex)
 
 #else
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help