1 Sep
2016
1 Sep
'16
8:37 a.m.
David Henningsson wrote:
- It is good practice to close pcm after usage
[...] 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;
Any previously created threads are already running. Calling some snd_* function on an already-closed device is worse than letting the OS clean up after the program exits.
If we'd wanted to be strictly correct, we would have to send a message to the threads and wait for them to exit (as the cleanup code below already does).
running = 0;
This variable should be volatile.
- for (i = 0; i < num_threads; i++)
for (i = 0; i < num_threads; i++) pthread_join(peeper_threads[i], NULL);pthread_cancel(peeper_threads[i]);
Regards, Clemens