Make an ACTOR run in another thread

I’m currently using Flow to develop a system, but single-threaded ACTOR seems to be a bottleneck here, like below, is it possible to make func1 and func2 running in different threads?

ACTOR Future<Void> test() {
    state ActorCollection add_actors(false);          

    loop {
        choose {
            when(wait(add_actors.getResult())) {}                

Unfortunately, this is not possible. ACTORs depend on the single “network” thread for scheduling and handling futures/callbacks, which cannot simply work with two threads, i.e., synchronization issues.

1 Like

There is not a straightforward way to do this with actors, but you can do it with some other methods. In theory you could potentially run multiple flow network threads and schedule work on particular ones, though in practice this is probably difficult because of various global state. And even if you could do it, it probably wouldn’t work so straightforwardly as you’ve written above.

Another option is to run other non-flow threads and schedule work on them. You wouldn’t be able to use actors for the work that gets farmed out, but if structured correctly you could still have actors waiting on the result. I think there are some examples of this in AsyncFileEIO.h where some work is scheduled on a thread pool and then the main thread polls for completion. There is some trickiness here in making sure that you are always signaling promises from the main thread.

I don’t know much about it, but it’s possible the rocks DB key-value store also has a similar construct for its threads.

1 Like