Opened 9 years ago
Closed 9 years ago
#8955 closed Feature Requests (fixed)
Request for more efficient way to get exception_ptr from future
| Reported by: | Niall Douglas | Owned by: | viboes |
|---|---|---|---|
| Milestone: | Boost 1.55.0 | Component: | thread |
| Version: | Boost 1.54.0 | Severity: | Optimization |
| Keywords: | Cc: |
Description
Vicente,
Here is that Boost.Thread feature request for AFIO I mentioned a while ago. Here is the code example:
shared_future<std::shared_ptr<detail::async_io_handle>> *thisresult=state.first->outsharedstates[idx].get();
// This seems excessive but I don't see any other legal way to extract the exception ...
bool success=false;
try
{
// Always must wait on the others, because some may be between decrementing the
// atomic and returning their result to here. Any waiting is likely short.
thisresult->get();
success=true;
}
catch(...)
{
exception_ptr e(afio::make_exception_ptr(afio::current_exception()));
assert(e);
complete_async_op(s.out[idx].first, s.out[idx].second, e);
}
if(success)
complete_async_op(s.out[idx].first, s.out[idx].second);
Taken from https://github.com/BoostGSoC/boost.afio/blob/master/libs/afio/src/afio.cpp#L1027
Basically, we need to scan a sequence of futures for any exception states which right now means trying to get() from each and try...catch to grab any exception_ptr's. As this is inefficient, is there any chance of adding a new member function to future and shared_future: get_exception()? This is identical to get(), except it returns any exception state instead of throwing it. If there is no exception state, it returns a null exception_ptr.
In other words, a very simple new feature, but one which lets us eliminate a lot of needless try...catch stanzas.
My thanks in advance Vicente.
Niall
Change History (3)
comment:1 by , 9 years ago
| Milestone: | Boost 1.55.0 → To Be Determined |
|---|---|
| Owner: | changed from to |
| Status: | new → assigned |
comment:2 by , 9 years ago
| Milestone: | To Be Determined → Boost 1.55.0 |
|---|
comment:3 by , 9 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
Committed revision [85666].

Committed revision [85644].