[master] 9e0f29c Attempt to close a theoretical race, which POSIX_MISTAKE makes it impossible to deal with correctly.

Poul-Henning Kamp phk at varnish-cache.org
Tue Dec 27 15:56:52 CET 2011


commit 9e0f29cdcdb3c96ac559692f21bdeaa7ecc9272a
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Dec 27 14:55:59 2011 +0000

    Attempt to close a theoretical race, which POSIX_MISTAKE makes it
    impossible to deal with correctly.
    
    Pointed out by:		Dong Feng

diff --git a/bin/varnishd/cache/cache_lck.c b/bin/varnishd/cache/cache_lck.c
index cff9845..2910582 100644
--- a/bin/varnishd/cache/cache_lck.c
+++ b/bin/varnishd/cache/cache_lck.c
@@ -98,6 +98,17 @@ Lck__Unlock(struct lock *lck, const char *p, const char *f, int l)
 	assert(pthread_equal(ilck->owner, pthread_self()));
 	AN(ilck->held);
 	ilck->held = 0;
+	/*
+	 * #ifdef POSIX_STUPIDITY:
+	 * The pthread_t type has no defined assignment or comparison
+	 * operators, this is why pthread_equal() is necessary.
+	 * Unfortunately POSIX forgot to define a NULL value for pthread_t
+	 * so you can never unset a pthread_t variable.
+	 * We hack it and fill it with zero bits, hoping for sane
+	 * implementations of pthread.
+	 * #endif
+	 */ 
+	memset(&ilck->owner, 0, sizeof ilck->owner);
 	AZ(pthread_mutex_unlock(&ilck->mtx));
 	if (cache_param->diag_bitmap & 0x8)
 		VSL(SLT_Debug, 0, "MTX_UNLOCK(%s,%s,%d,%s)", p, f, l, ilck->w);



More information about the varnish-commit mailing list