Skip to content

Instantly share code, notes, and snippets.

@ra1u
Created December 10, 2016 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ra1u/5b88b416c1a57adf50c2daa159757b71 to your computer and use it in GitHub Desktop.
Save ra1u/5b88b416c1a57adf50c2daa159757b71 to your computer and use it in GitHub Desktop.
#include <string>
#include <iostream>
#include "caf/all.hpp"
#include <vector>
using namespace caf;
actor_system_config g_cfg;
actor_system g_system{g_cfg};
static void tree_final(blocking_actor *self, const actor &a_receiver,
int64_t n) {
self->send(a_receiver, n);
}
void tree(blocking_actor *self, const actor &a_receiver, int64_t d, int64_t n) {
int64_t v = n * 10;
if (d == 0) {
for (int64_t i = 0; i < 10; ++i) {
g_system.spawn(tree_final, self, v + i);
}
} else {
for (int64_t i = 0; i < 10; ++i) {
g_system.spawn(tree, self, d - 1, v + i);
}
}
int i = 0;
int64_t total = 0;
self->receive_for(i,10)([&](int64_t c) {
total += c;
});
self->send(a_receiver, total);
}
void master(blocking_actor *self) {
self->receive(
[=](int64_t c) { std::cout << "got master " << c << std::endl; });
}
int main() {
actor mirror_actor = g_system.spawn(master);
// aiming for n = 5
const int64_t N = 5;
g_system.spawn(tree, mirror_actor, N, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment