[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Mon, 12 Dec 2011 15:15:45 +0800
From: Lai Jiangshan <laijs@...fujitsu.com>
To: Pekka Enberg <penberg@...nel.org>, Ingo Molnar <mingo@...e.hu>
Cc: linux-kernel@...r.kernel.org, Lai Jiangshan <laijs@...fujitsu.com>
Subject: [PATCH 01/11] kvm tools: check condition before wait
We should check the condition before wait it,
otherewise we may get deadlock.
Signed-off-by: Lai Jiangshan <laijs@...fujitsu.com>
---
tools/kvm/threadpool.c | 7 +++----
1 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/tools/kvm/threadpool.c b/tools/kvm/threadpool.c
index fdc5fa7..2e59e62 100644
--- a/tools/kvm/threadpool.c
+++ b/tools/kvm/threadpool.c
@@ -80,12 +80,11 @@ static void *thread_pool__threadfunc(void *param)
struct thread_pool__job *curjob;
mutex_lock(&job_mutex);
- pthread_cond_wait(&job_cond, &job_mutex);
- curjob = thread_pool__job_pop();
+ while ((curjob = thread_pool__job_pop()) == NULL)
+ pthread_cond_wait(&job_cond, &job_mutex);
mutex_unlock(&job_mutex);
- if (curjob)
- thread_pool__handle_job(curjob);
+ thread_pool__handle_job(curjob);
}
pthread_cleanup_pop(0);
--
1.7.4.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists