Thread (13 messages) flat view 13 messages, 5 authors, 2016-06-15

Re: [PATCH/RFC] mingw: implement PTHREAD_MUTEX_INITIALIZER

From: Johannes Sixt <hidden>
Date: 2016-06-15 22:52:19

Am 10/25/2011 16:55, schrieb Erik Faye-Lund:
+int pthread_mutex_lock(pthread_mutex_t *mutex)
+{
+	if (mutex->autoinit) {
+		if (InterlockedCompareExchange(&mutex->autoinit, -1, 1) != -1) {
+			pthread_mutex_init(mutex, NULL);
+			mutex->autoinit = 0;
+		} else
+			while (mutex->autoinit != 0)
+				; /* wait for other thread */
+	}
The double-checked locking idiom. Very suspicious. Can you explain why it
works in this case? Why are no Interlocked functions needed for the other
accesses of autoinit? ("It is volatile" is the wrong answer to this last
question, BTW.)

-- Hannes
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help