From d9ce918c418234912f66ea4c9eac7270c3e20f80 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 24 Jun 2022 21:11:51 +0200 Subject: [PATCH] Small test tool for PBD::Transmitter thread-safety tests Launch as ``` ./session_utils/run ardour7-debug_transmitter ./session_utils/debug ardour7-debug_transmitter ``` --- session_utils/debug_transmitter.cc | 71 ++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 session_utils/debug_transmitter.cc diff --git a/session_utils/debug_transmitter.cc b/session_utils/debug_transmitter.cc new file mode 100644 index 0000000000..90a7eaeec3 --- /dev/null +++ b/session_utils/debug_transmitter.cc @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2022 Robin Gareus + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include +#include + +#include "common.h" + +#include "pbd/error.h" +#include "pbd/semutils.h" + +using namespace std; +using namespace ARDOUR; +using namespace SessionUtils; + +PBD::Semaphore sem ("sync", 0); + +void worker (int i) +{ + sem.wait (); + PBD::error << "Thread: " << i << endmsg; +} + +int main (int argc, char* argv[]) +{ + SessionUtils::init(); + + int n_thread = 0; + + if (argc > 1) { + n_thread = atoi (argv[1]); + } + + if (n_thread < 1 || n_thread > 512) { + n_thread = 16; + } + + printf ("Starting %d threads\n", n_thread); + + std::vector threads; + for (int c = 0; c < n_thread; ++c) { + threads.push_back (std::thread (worker, c + 1)); + } + + for (size_t c = 0; c < threads.size (); ++c) { + sem.signal (); + } + + for (auto& th : threads) { + th.join (); + } + + SessionUtils::cleanup(); + return 0; +}