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

Fix a strange thing in parallel::detail::handle_exception. (Fix #2834.) #3089

Merged
merged 4 commits into from Jan 8, 2018

Conversation

taeguk
Copy link
Member

@taeguk taeguk commented Jan 1, 2018

Fixes #2834 .
flyby: Fixes #3088 .

@hkaiser
Copy link
Member

hkaiser commented Jan 1, 2018

@taeguk Thanks for looking into this! It's overdue that you get access to the repository - I've sent you an invite.

@@ -201,19 +202,22 @@ namespace hpx { namespace parallel { inline namespace v1
result = execution::async_execute(policy.executor(),
&sort_thread<ExPolicy, RandomIt, Compare>,
std::ref(policy), first, last, comp);

return result;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't a simple

return execution::async_execute(policy.executor(),  
    &sort_thread<ExPolicy, RandomIt, Compare>,  
    std::ref(policy), first, last, comp);

do the trick here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hkaiser You're right. That code was derived from just moving return result; into inside of try block. I'll fix that like you said.

catch (...) {
return hpx::make_exceptional_future<RandomIt>(
std::current_exception());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, do we really have to use nested try/catch blocks here? handle_local_exceptions only rethrows the current exception as an exception list. Couldn't we directly call make_exceptional_future with a exception list constructed from the current exception?

Copy link
Member Author

@taeguk taeguk Jan 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hkaiser handle_local_exceptions() handles an exception differently when std::current_exception() means std::bad_alloc. In that case, handle_local_exceptions() just rethrows std::bad_alloc without wrapping into exception_list.
We need to handle the exception differently according to what is the exception which we handles. And for that, I used handle_local_exception().
And nested catch (Line216-219) is needed for wrapping an exception which is threw properly from handle_local_exception().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@taeguk yes, I understand. Still, there might be a better way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hkaiser Aha, okay i got it.
https://github.com/taeguk/hpx/blob/9d72e4de54495987597bc2e6bbe609bc8125a01c/hpx/parallel/algorithms/sort.hpp#L249-L260
If we move that exception handling from Line208 to above lines, we can avoid nested try/catch blocks with just calling detail::handle_exception().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

catch (hpx::exception_list const& el) {
throw el;
catch (hpx::exception_list const&) {
throw;
}
catch (...) {
throw hpx::exception_list(std::current_exception());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this looks really strange (it probably was strange all along). I'm sure this can be done with one level of try/catch blocks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hkaiser Yes, we can do that with only one level of try/catch blocks.

Copy link
Member

@hkaiser hkaiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, thanks a lot!

@hkaiser hkaiser merged commit 092422f into STEllAR-GROUP:master Jan 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants