-
Notifications
You must be signed in to change notification settings - Fork 65
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
Executor of packaged_task not used in reduction #502
Comments
In the second example, I wouldn't expect your check to trigger your custom executor because that would only apply as the default executor for subsequent continuations (except it doesn't... more on that in a moment). There was a change in the implementation of reducing where it was picking up the prior default executor for the reduce continuation - it now uses the immediate executor. But the result is that the default executor of When you say
Do you have a preference for 1 or 2? |
If I am understanding correctly then I think 2 would be the better option. It would allow for a very simple and consistent rule on executors. When dealing with futures, executors would only be used to dispatch new tasks via Would that affect cancellation in any way? If you wanted to force the future of your packaged_task to run on a particular executor you could simply wrap I agree that the immediate executor is probably the right thing to do most of the time. There is also a chance that this could simplify a lot of code. It would make executor changes rare and explicit. |
|
I think most of the time having calls to This would mean that you would have to call |
I got that wrong - the continuation will always go through the executor held by the future (or the supplied executor) even if the future is ready. I ran a quick test to verify. auto f = stlab::make_ready_future(5, [](auto task){ cout << "invoked: "; task(); });
auto f1 = f | [](int x){ cout << x << endl; }; Outputs:
|
The continuation will go through the executor held by the future iff there is no reduction. auto f = stlab::make_ready_future(5, [](auto task){ cout << "original_executor: "; task(); });
cout << "back on calling context" << endl;
auto f1 = f | [](int x){ cout << x << endl; }; Outputs:
That is expected. But if you add a reduction: auto f = stlab::make_ready_future(5, [](auto task){ cout << "original_executor: "; task(); }).then([](int x){ return stlab::make_ready_future(x, [](auto task){ cout << "reduced_executor: "; task(); }); });;
cout << "back on calling context" << endl;
auto f1 = f | [](int x){ cout << x << endl; }; Outputs:
I would at least expect it to use |
From 2.0.0a1 release I get the following output:
This is basically correct, but I think should be made more efficient - here is an explanation with notes.
Returns a future with the "original executor" as the default for continuations.
The continuation is executed on the original executor and prints:
This is correct behavior. The internal result of the The reduction attaches a continuation to the outer future. This executes and prints another Then we print I'm going to make the changes to eliminate the unnecessary executors (replace with immediate) in the above and write a unit test. I'm leaving this issue open until that lands in main. |
I am not sure what the intended functionality is here but it was my understanding that the executor passed to
stlab::package()
would be used when executing a continuation.Does a future reduction not count as a continuation?
I think it did in 1.6.2 since I now have code that doesn't work when I updated to 1.7.1.
Should I update my usage or was this change unintended?
The text was updated successfully, but these errors were encountered: