4 ms·
You’ve just described Actors. Now take the next step and add a work stealing schedular for a fuller Actor system.
by smallstepforman 4y ago
You’ve just described Actors. Now take the next step and add a work stealing schedular for a fuller Actor system.
- MontagFTB 4y agoI’ve been toying with these lately, too. My solution was to give each actor an executor where it will run: actor<int> foo(stlab::default_executor, “name”, 42); auto f = foo.send([](auto& x){ std::cout << x << ‘\n’; // prints 42 }); Each call to ‘send’ returns a stlab::future which can have a continuation chained, etc. The nice thing about these is the executor based interface is generic. The actor could be dedicated to a thread, run on an OS-provided thread pool, etc. At the time the actor is running, the thread it is on is temporarily given the name of the actor to ease debugging.
- quietbritishjim 4y agoAlmost. If each thread were an Actor (I think that's what you're saying?) then that would structure the code around each type of work e.g. here is the code for all the database operations. That's not a very useful way to group things for the developer. The way I wrote it above, the code is structured around a single activity across all the types of work it has to do.