Skip to content

Minimal example for spawning NUM_CPU threads and running an app instance on each? #674

Answered by npuichigo
GavinRay97 asked this question in Q&A
Discussion options

You must be logged in to vote

Something like this?

int main()
{
  auto num_cpus = std::thread::hardware_concurrency();
  exec::static_thread_pool pool(num_cpus);

  auto make_snd = [&]() {
    return ex::schedule(pool.get_scheduler()) 
         | ex::then([]{
             MyApplication app;
             app.run();
           });
  }
  auto snd = ex::when_all(
    make_snd(),
    make_snd(),
    make_snd()
  )
  stdexec::sync_wait(std::move(snd));
}

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@GavinRay97
Comment options

@npuichigo
Comment options

Answer selected by GavinRay97
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants