Modify

Opened 4 years ago

Closed 4 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

Attachments (0)

Change History (3)

comment:1 Changed 4 years ago by viboes

Milestone: Boost 1.55.0To Be Determined
Owner: changed from Anthony Williams to viboes
Status: newassigned

comment:2 Changed 4 years ago by viboes

Milestone: To Be DeterminedBoost 1.55.0

Committed revision [85644].

comment:3 Changed 4 years ago by viboes

Resolution: fixed
Status: assignedclosed

Committed revision [85666].

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain viboes.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.