MCPcopy Create free account
hub / github.com/boostorg/asio / main

Function main

example/cpp11/executors/actor.cpp:258–286  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

256};
257
258int main()
259{
260 const std::size_t num_threads = 16;
261 const int num_hops = 50000000;
262 const std::size_t num_actors = 503;
263 const int token_value = (num_hops + num_actors - 1) / num_actors;
264 const std::size_t actors_per_thread = num_actors / num_threads;
265
266 struct single_thread_pool : thread_pool { single_thread_pool() : thread_pool(1) {} };
267 single_thread_pool pools[num_threads];
268 std::vector<std::shared_ptr<member>> members(num_actors);
269 receiver<int> rcvr;
270
271 // Create the member actors.
272 for (std::size_t i = 0; i < num_actors; ++i)
273 members[i] = std::make_shared<member>(pools[(i / actors_per_thread) % num_threads].get_executor());
274
275 // Initialise the actors by passing each one the address of the next actor in the ring.
276 for (std::size_t i = num_actors, next_i = 0; i > 0; next_i = --i)
277 send(members[next_i]->address(), rcvr.address(), members[i - 1]->address());
278
279 // Send exactly one token to each actor, all with the same initial value, rounding up if required.
280 for (std::size_t i = 0; i < num_actors; ++i)
281 send(token_value, rcvr.address(), members[i]->address());
282
283 // Wait for all signal messages, indicating the tokens have all reached zero.
284 for (std::size_t i = 0; i < num_actors; ++i)
285 rcvr.wait();
286}

Callers

nothing calls this directly

Calls 3

get_executorMethod · 0.45
addressMethod · 0.45
waitMethod · 0.45

Tested by

no test coverage detected