From 955705a4ef6b69e246914ed6330a713b4c13ccf4 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 9 Mar 2014 15:21:00 +0100 Subject: [PATCH] ao_write: Join threads before returning an error from aow_post_select(). This guarantees the play thread is not active any more in aow_close(). --- ao_write.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ao_write.c b/ao_write.c index af688242..4281f536 100644 --- a/ao_write.c +++ b/ao_write.c @@ -40,10 +40,7 @@ static void aow_close(struct writer_node *wn) if (!pawd) return; - if (pawd->thread_btrn) { - pthread_cancel(pawd->thread); - pthread_join(pawd->thread, NULL); - } + assert(!pawd->thread_btrn); ao_close(pawd->dev); free(pawd); wn->private_data = NULL; @@ -352,8 +349,10 @@ static int aow_post_select(__a_unused struct sched *s, return 0; } if (!wn->btrn) { - if (!pawd->thread_btrn) + if (!pawd->thread_btrn) { + pthread_join(pawd->thread, NULL); return -E_AO_EOF; + } PARA_INFO_LOG("waiting for play thread to terminate\n"); return 0; } -- 2.39.2