push pull: can now pass ProducerCount on the command line

This commit is contained in:
Florian Lüke 2024-05-07 14:56:25 +02:00
parent 68ce15fedf
commit a423e602aa

View file

@ -144,6 +144,11 @@ int main(int argc, char *argv[])
{
spdlog::set_level(spdlog::level::info);
size_t ProducerCount = 10;
if (argc > 1)
ProducerCount = std::stoull(argv[1]);
nng_socket consumerSocket = NNG_SOCKET_INITIALIZER;
if (int res = nng_pull0_open(&consumerSocket))
@ -162,10 +167,13 @@ int main(int argc, char *argv[])
std::vector<std::thread> threads;
const size_t ProducerCount = 10;
spdlog::info("Starting {} producers.", ProducerCount);
for (size_t i=0; i<ProducerCount; ++i)
threads.emplace_back(std::thread(push_producer, producerSocket, i));
spdlog::info("Starting consumer.");
// Deliberately start the consumer after the producers. There should be no buffer loss.
threads.emplace_back(std::thread(pull_consumer, consumerSocket));