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

Function main

example/cpp14/executors/actor.cpp:257–285  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

get_executorMethod · 0.45
addressMethod · 0.45
waitMethod · 0.45

Tested by

no test coverage detected