[PATCH 01/11] kvm tools: check condition before wait

From: Lai Jiangshan
Date: Mon Dec 12 2011 - 02:15:18 EST


We should check the condition before wait it,
otherewise we may get deadlock.

Signed-off-by: Lai Jiangshan <laijs@xxxxxxxxxxxxxx>
---
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@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/