[alsa-devel] [PATCH] test/pcm-multi-thread: Remove pthread_cancel, add snd_pcm_close
David Henningsson
diwic at ubuntu.com
Thu Sep 1 04:23:26 CEST 2016
Because
1) Apparently, our thread cancellation policy is
"don't even think about it" and we shouldn't break
our own rules
2) It is good practice to close pcm after usage
Signed-off-by: David Henningsson <diwic at ubuntu.com>
---
test/pcm-multi-thread.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/test/pcm-multi-thread.c b/test/pcm-multi-thread.c
index da1b87c..26de7db 100644
--- a/test/pcm-multi-thread.c
+++ b/test/pcm-multi-thread.c
@@ -219,18 +219,22 @@ int main(int argc, char **argv)
return 1;
}
- if (setup_params())
+ if (setup_params()) {
+ snd_pcm_close(pcm);
return 1;
+ }
buf = calloc(1, snd_pcm_format_size(format, bufsize) * channels);
if (!buf) {
fprintf(stderr, "cannot alloc buffer\n");
+ snd_pcm_close(pcm);
return 1;
}
for (i = 0; i < num_threads; i++) {
if (pthread_create(&peeper_threads[i], NULL, peeper, (void *)(long)i)) {
fprintf(stderr, "pthread_create error\n");
+ snd_pcm_close(pcm);
return 1;
}
}
@@ -255,9 +259,8 @@ int main(int argc, char **argv)
running = 0;
for (i = 0; i < num_threads; i++)
- pthread_cancel(peeper_threads[i]);
- for (i = 0; i < num_threads; i++)
pthread_join(peeper_threads[i], NULL);
+ snd_pcm_close(pcm);
return 1;
}
--
1.9.1
More information about the Alsa-devel
mailing list