From c416ed4cb200fba9e6f9ac1f45d561387e602608 Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Tue, 20 Jan 2009 21:07:57 -0500 Subject: [PATCH] Create the client_msg_thread and client_msg_sender_thread as joinable and wait for them to complete in cleanup_cb(). --- src/common.h | 1 - src/pwmd.c | 13 ++++--------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/common.h b/src/common.h index 0f6ef17a..a20d432d 100644 --- a/src/common.h +++ b/src/common.h @@ -143,7 +143,6 @@ struct client_thread_s { pthread_cond_t msg_sender_cond; pthread_mutex_t msg_sender_mutex; gint msg_fd[2]; - gboolean quit; gchar *name; gint fd; struct client_s *cl; diff --git a/src/pwmd.c b/src/pwmd.c index a4dff0b5..ce32f623 100644 --- a/src/pwmd.c +++ b/src/pwmd.c @@ -490,9 +490,10 @@ static void cleanup_cb(void *arg) pthread_mutex_lock(&cn_mutex); log_write(N_("exiting, fd=%i"), cn->fd); - cn->quit = TRUE; pthread_cancel(cn->msg_tid); + pthread_join(cn->msg_tid, NULL); pthread_cancel(cn->msg_sender_tid); + pthread_join(cn->msg_sender_tid, NULL); close(cl->thd->msg_fd[0]); close(cl->thd->msg_fd[1]); pthread_join(cn->tid, NULL); @@ -566,9 +567,7 @@ static void *client_msg_sender_thread(void *arg) gpg_error_t rc; pthread_cond_wait(&thd->msg_sender_cond, &thd->msg_sender_mutex); - - if (thd->quit) - break; + pthread_testcancel(); /* The messages may have been stacked while waiting for send_status() * to return. Send what's in the queue. */ @@ -617,10 +616,7 @@ static void *client_msg_thread(void *arg) struct status_msg_s *msg; pthread_cond_wait(&thd->msg_cond, &thd->msg_mutex); - - if (thd->quit) - break; - + pthread_testcancel(); FD_ZERO(&rfds); FD_SET(thd->msg_fd[0], &rfds); n = select(thd->msg_fd[0]+1, &rfds, NULL, NULL, NULL); @@ -743,7 +739,6 @@ static void *client_thread(void *data) pthread_cond_init(&thd->msg_cond, NULL); pthread_mutex_init(&thd->msg_mutex, NULL); pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); pthread_create(&thd->msg_tid, &attr, client_msg_thread, thd); pthread_cond_init(&thd->msg_sender_cond, NULL); -- 2.11.4.GIT