Previous protection scheme of wi->nr_thread in work.c was
unclear. This patch let work.c protect wi->nr_thread by
wi->startup_lock.

Signed-off-by: Hitoshi Mitake <[email protected]>
---
 lib/work.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/work.c b/lib/work.c
index 84eb727..a71f139 100644
--- a/lib/work.c
+++ b/lib/work.c
@@ -293,7 +293,11 @@ static void *worker_routine(void *arg)
 
                pthread_mutex_lock(&wi->pending_lock);
                if (wq_need_shrink(wi)) {
+                       pthread_mutex_unlock(&wi->pending_lock);
+
+                       pthread_mutex_lock(&wi->startup_lock);
                        wi->nr_threads--;
+                       pthread_mutex_unlock(&wi->startup_lock);
 
 #ifdef ENABLE_TRACE
                        pthread_mutex_lock(&tid_map_lock);
@@ -301,7 +305,6 @@ static void *worker_routine(void *arg)
                        pthread_mutex_unlock(&tid_map_lock);
 #endif
 
-                       pthread_mutex_unlock(&wi->pending_lock);
                        pthread_detach(pthread_self());
                        sd_debug("destroy thread %s %d, %zu", wi->name, tid,
                                 wi->nr_threads);
-- 
1.8.1.2

-- 
sheepdog mailing list
[email protected]
http://lists.wpkg.org/mailman/listinfo/sheepdog

Reply via email to