[master] 4711b4b 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.

Poul-Henning Kamp phk at varnish-cache.org
Wed Aug 22 12:02:06 CEST 2012


commit 4711b4b3187b7088c841aedaf56797997ffef6fe
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/storage_persistent.c b/bin/varnishd/storage/storage_persistent.c
index 6118fbf..b4e8c8c 100644
--- a/bin/varnishd/storage/storage_persistent.c
+++ b/bin/varnishd/storage/storage_persistent.c
@@ -275,6 +275,7 @@ smp_thread(struct worker *wrk, void *priv)
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	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)
@@ -305,6 +306,7 @@ static void
 smp_open(const struct stevedore *st)
 {
 	struct smp_sc	*sc;
+	pthread_t pt;
 
 	ASSERT_CLI();
 
@@ -346,7 +348,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