[3.0] d420192 Fix a race condition, the child thread could get to the first assert before the parent carried out the assignment of the thread id to the variable.

Tollef Fog Heen tfheen at varnish-cache.org
Mon Apr 22 13:27:00 CEST 2013


commit d4201928a2b86858810d149293c4b754d612ed01
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Aug 22 10:01:19 2012 +0000

    Fix a race condition, the child thread could get to the first
    assert before the parent carried out the assignment of the thread
    id to the variable.
    
    Detected by:	OSX

diff --git a/bin/varnishd/storage_persistent.c b/bin/varnishd/storage_persistent.c
index a4ba598..8acbc20 100644
--- a/bin/varnishd/storage_persistent.c
+++ b/bin/varnishd/storage_persistent.c
@@ -275,6 +275,7 @@ smp_thread(struct sess *sp, void *priv)
 
 	(void)sp;
 	CAST_OBJ_NOTNULL(sc, priv, SMP_SC_MAGIC);
+	sc->thread = pthread_self();
 
 	/* First, load all the objects from all segments */
 	VTAILQ_FOREACH(sg, &sc->segments, list)
@@ -306,6 +307,7 @@ static void
 smp_open(const struct stevedore *st)
 {
 	struct smp_sc	*sc;
+	pthread_t pt;
 
 	ASSERT_CLI();
 
@@ -347,7 +349,7 @@ smp_open(const struct stevedore *st)
 	smp_new_seg(sc);
 
 	/* Start the worker silo worker thread, it will load the objects */
-	WRK_BgThread(&sc->thread, "persistence", smp_thread, sc);
+	WRK_BgThread(&pt, "persistence", smp_thread, sc);
 
 	VTAILQ_INSERT_TAIL(&silos, sc, list);
 	Lck_Unlock(&sc->mtx);



More information about the varnish-commit mailing list