diff mbox

[30/42] Fix race condition in stop_waiter_thread()

Message ID 1357653259-62650-31-git-send-email-hare@suse.de (mailing list archive)
State Deferred, archived
Headers show

Commit Message

Hannes Reinecke Jan. 8, 2013, 1:54 p.m. UTC
The signal handler might run before we had a chance to
set the 'waiter' context to '0', so better do it previously.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 libmultipath/waiter.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
diff mbox

Patch

diff --git a/libmultipath/waiter.c b/libmultipath/waiter.c
index 076539c..da71543 100644
--- a/libmultipath/waiter.c
+++ b/libmultipath/waiter.c
@@ -45,6 +45,8 @@  void free_waiter (void *data)
 
 void stop_waiter_thread (struct multipath *mpp, struct vectors *vecs)
 {
+	pthread_t thread;
+
 	if (mpp->waiter == (pthread_t)0) {
 		condlog(3, "%s: event checker thread already stopped",
 			mpp->alias);
@@ -52,8 +54,9 @@  void stop_waiter_thread (struct multipath *mpp, struct vectors *vecs)
 	}
 	condlog(2, "%s: stop event checker thread (%lu)", mpp->alias,
 		mpp->waiter);
-	pthread_cancel(mpp->waiter);
+	thread = mpp->waiter;
 	mpp->waiter = (pthread_t)0;
+	pthread_cancel(thread);
 }
 
 /*