push pull: can now pass ProducerCount on the command line
This commit is contained in:
parent
68ce15fedf
commit
a423e602aa
1 changed files with 9 additions and 1 deletions
|
@ -144,6 +144,11 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
spdlog::set_level(spdlog::level::info);
|
spdlog::set_level(spdlog::level::info);
|
||||||
|
|
||||||
|
size_t ProducerCount = 10;
|
||||||
|
|
||||||
|
if (argc > 1)
|
||||||
|
ProducerCount = std::stoull(argv[1]);
|
||||||
|
|
||||||
nng_socket consumerSocket = NNG_SOCKET_INITIALIZER;
|
nng_socket consumerSocket = NNG_SOCKET_INITIALIZER;
|
||||||
|
|
||||||
if (int res = nng_pull0_open(&consumerSocket))
|
if (int res = nng_pull0_open(&consumerSocket))
|
||||||
|
@ -162,10 +167,13 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
std::vector<std::thread> threads;
|
std::vector<std::thread> threads;
|
||||||
|
|
||||||
const size_t ProducerCount = 10;
|
spdlog::info("Starting {} producers.", ProducerCount);
|
||||||
|
|
||||||
for (size_t i=0; i<ProducerCount; ++i)
|
for (size_t i=0; i<ProducerCount; ++i)
|
||||||
threads.emplace_back(std::thread(push_producer, producerSocket, 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.
|
// Deliberately start the consumer after the producers. There should be no buffer loss.
|
||||||
threads.emplace_back(std::thread(pull_consumer, consumerSocket));
|
threads.emplace_back(std::thread(pull_consumer, consumerSocket));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue