diff --git a/server/etc/snapserver.conf b/server/etc/snapserver.conf index cbb4977f..6bfe05be 100644 --- a/server/etc/snapserver.conf +++ b/server/etc/snapserver.conf @@ -18,9 +18,12 @@ # General server settings ##################################################### # [server] -# Number of threads to use -# For values <= 0 the number of threads will be 2 (on single and dual cores) -# or 4 (for quad and more cores) +# Number of additional worker threads to use +# - For values < 0 the number of threads will be 1 (on single cores), +# 2 (on dual cores) or 4 (for quad and more cores) +# - 0 will utilize just the processes main thread and might cause audio drops +# in case there are a couple of longer running tasks, such as encoding +# multiple audio streams #threads = -1 # ############################################################################### diff --git a/server/snapserver.cpp b/server/snapserver.cpp index 267f2e05..e1312a47 100644 --- a/server/snapserver.cpp +++ b/server/snapserver.cpp @@ -267,16 +267,21 @@ int main(int argc, char* argv[]) std::unique_ptr streamServer(new StreamServer(io_context, settings)); streamServer->start(); - if (num_threads <= 0) - num_threads = std::max(2, std::min(4, static_cast(std::thread::hardware_concurrency()))); + if (num_threads < 0) + num_threads = std::max(1, std::min(4, static_cast(std::thread::hardware_concurrency()))); LOG(INFO) << "number of threads: " << num_threads << ", hw threads: " << std::thread::hardware_concurrency() << "\n"; + + auto sig = install_signal_handler({SIGHUP, SIGTERM, SIGINT}, [&io_context](int signal, const std::string& name) { + SLOG(INFO) << "Received signal " << signal << ": " << name << "\n"; + io_context.stop(); + }); + std::vector threads; for (int n = 0; n < num_threads; ++n) threads.emplace_back([&] { io_context.run(); }); - auto sig = install_signal_handler({SIGHUP, SIGTERM, SIGINT}).get(); - SLOG(INFO) << "Received signal " << sig << ": " << strsignal(sig) << "\n"; - io_context.stop(); + io_context.run(); + for (auto& t : threads) t.join();