From b9dbfcc8f5a34cea02d97c047ebb24e057b146a3 Mon Sep 17 00:00:00 2001 From: Jeff Darcy Date: Thu, 10 Mar 2016 08:56:33 -0500 Subject: fdl: fix race during initialization There was a race between fdl_worker starting to run and setting this->private in fdl_init. This should never happen on a multiprocessor, since the new thread should start on a different core and creating it there should take many times longer than getting from pthread_create to the end of fdl_init on the original core. The only way it seems likely is if the new thread is started on the same core that's already in fdl_init, and the new thread preempts the old, which many would consider broken . . . but there are plenty of broken thread implementations and it's hardly surprising that glibc has one. Still, it's a race and it did show up in regression tests a few times, so it needs to be fixed. Change-Id: Ifa5b0ae1ec111860f0d3f55a98aa2b8f2cef84ca Signed-off-by: Jeff Darcy Reviewed-on: http://review.gluster.org/13674 Smoke: Gluster Build System NetBSD-regression: NetBSD Build System CentOS-regression: Gluster Build System Reviewed-by: Vijay Bellur --- xlators/experimental/fdl/src/fdl-tmpl.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/xlators/experimental/fdl/src/fdl-tmpl.c b/xlators/experimental/fdl/src/fdl-tmpl.c index 8fcc6a8d6f..fdcfafbac3 100644 --- a/xlators/experimental/fdl/src/fdl-tmpl.c +++ b/xlators/experimental/fdl/src/fdl-tmpl.c @@ -417,12 +417,7 @@ fdl_init (xlator_t *this) GF_OPTION_INIT ("log-path", priv->log_dir, path, err); - if (pthread_create(&priv->worker,NULL,fdl_worker,this) != 0) { - gf_log (this->name, GF_LOG_ERROR, - "failed to start fdl_worker"); - goto err; - } - + this->private = priv; /* * The rest of the fop table is automatically generated, so this is a * bit cleaner than messing with the generation to add a hand-written @@ -430,7 +425,12 @@ fdl_init (xlator_t *this) */ this->fops->ipc = fdl_ipc; - this->private = priv; + if (pthread_create(&priv->worker,NULL,fdl_worker,this) != 0) { + gf_log (this->name, GF_LOG_ERROR, + "failed to start fdl_worker"); + goto err; + } + return 0; err: -- cgit