From 084c2963621b08d87ac876a6b2ac2b636409a3d7 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Thu, 31 Dec 2020 02:14:12 -0700 Subject: [PATCH] Piano: Quit the audio thread by checking Core::EventLoop for exit The infinite loop here doesn't really work at all for an application process that expects to be able to exit. Check against Core::EventLoop::current() to see if it's time to exit, and return 0 from the thread function if so. The thread will be joined in its destructor, which doesn't assert anymore now that Thread is a jthread. --- Applications/Piano/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Applications/Piano/main.cpp b/Applications/Piano/main.cpp index 121f1eec0d..04bf0d4cd5 100644 --- a/Applications/Piano/main.cpp +++ b/Applications/Piano/main.cpp @@ -82,7 +82,7 @@ int main(int argc, char** argv) } Array buffer; - for (;;) { + while (!Core::EventLoop::current().was_exit_requested()) { track_manager.fill_buffer(buffer); audio->write(reinterpret_cast(buffer.data()), buffer_size); Core::EventLoop::current().post_event(main_widget, make(0)); @@ -101,6 +101,7 @@ int main(int argc, char** argv) wav_writer.finalize(); } } + return 0; }); audio_thread->start();