Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to manually run a queued task in the current thread? #17

Open
magiblot opened this issue Jun 8, 2020 · 2 comments
Open

Comments

@magiblot
Copy link

magiblot commented Jun 8, 2020

Hi,

I am trying to parallelize a library with a synchronous interface, preserving backwards compatibility. Even if the interface doesn't use Futures, I could still do something like this:

Frame Clip::getFrame() {
    Frame frame = /* */;
    if (task_not_ran)
        frame.plane = queue_task();
    return frame;
}

Plane Frame::getPlane() {
    while (!plane.isCompleted()) {
        wait_first_of(plane, tasks_pending);
        if (!plane.isCompleted())
            run_pending_task();
        else
            break;
    }
    return plane.result();
}

The idea is: since the current task has to wait for a result but cannot be evicted from the thread, it can run pending tasks recursively until the result is ready.

This is obviously worse than having a fully asynchronous interface, but could make it possible to parallelize already existing code and binaries.

Is such a thing possible?

Thanks.

@dkormalev
Copy link
Owner

It is not possible with how it works now. I can't guarantee that such thing will be supported (and when if yes), but it at least gave me some food for thoughts, thank you for this.

@magiblot
Copy link
Author

magiblot commented Jun 9, 2020

Hi Dennis, thanks for the quick response. I am also looking into other libraries such as HPX, so I suggest you not to spend time implementing this unless it is actually useful to you.
Cheers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants