Comments (7)
I don't know if this is the preferred way, but I have made the attached patch for this reason.
Index: boost/fiber/future/future.hpp
===================================================================
--- boost/fiber/future/future.hpp (revision 4246)
+++ boost/fiber/future/future.hpp (revision 4247)
@@ -152,7 +152,7 @@
shared_future< R & > share();
- R & get() {
+ R get() {
if ( ! valid() ) {
throw future_uninitialized();
}
Index: boost/fiber/future/detail/shared_state.hpp
===================================================================
--- boost/fiber/future/detail/shared_state.hpp (revision 4246)
+++ boost/fiber/future/detail/shared_state.hpp (revision 4247)
@@ -81,12 +81,12 @@
mark_ready_and_notify_( lk);
}
- R const& get_( std::unique_lock< mutex > & lk) {
+ R get_( std::unique_lock< mutex > & lk) {
wait_( lk);
if ( except_) {
std::rethrow_exception( except_);
}
- return value_.get();
+ return std::move(value_.get());
}
std::exception_ptr get_exception_ptr_( std::unique_lock< mutex > & lk) {
@@ -161,7 +161,7 @@
set_exception_( except, lk);
}
- R const& get() {
+ R get() {
std::unique_lock< mutex > lk( mtx_);
return get_( lk);
}
from fiber.
unfortunately it is not fixed yet
the C++ standard requires signature R & future< R & >::get()
from fiber.
Can you help me understand?
This code compiles fine:
#include <iostream>
#include <future>
struct A {
A() = default;
A(A const&) = delete;
A(A&&) = default;
int value;
};
int main() {
using namespace std;
promise<A> p;
auto future = p.get_future();
std::cout << future.get().value << std::endl;
}
So I don't understand your comment about the C++ standard
from fiber.
my comment was related to the comment of BenPope
from fiber.
The standard (ยง 30.6.6.13) requires:
R future<R>::get();
R& future<R&>::get();
void future<void>::get();
I believe I corrected the signature for future< R >, leaving future< R& > alone.
Update: I was wrong, looks like I messed up the patch to future.hpp, but the one to shared_state still seems valid. If I make a pull request, against which branch would you prefer?
from fiber.
What do you think about this patch? It introduces a small asymmetry in the
implementations of future::get and shared_future::get but the observable
behaviour should be preserved.
diff -u -r ./detail/shared_state.hpp ../../../../../support/deps/include/boost/fiber/future/detail/shared_state.hpp
--- ./detail/shared_state.hpp 2015-10-14 19:17:13.169202093 +0200
+++ ../../../../../support/deps/include/boost/fiber/future/detail/shared_state.hpp 2015-10-14 19:28:04.844428815 +0200
@@ -89,6 +89,14 @@
return value_.get();
}
+ R detach_( std::unique_lock< mutex > & lk) {
+ wait_( lk);
+ if ( except_) {
+ std::rethrow_exception( except_);
+ }
+ return std::move(value_.get());
+ }
+
std::exception_ptr get_exception_ptr_( std::unique_lock< mutex > & lk) {
wait_( lk);
return except_;
@@ -166,6 +174,11 @@
return get_( lk);
}
+ R detach() {
+ std::unique_lock< mutex > lk( mtx_);
+ return detach_( lk);
+ }
+
std::exception_ptr get_exception_ptr() {
std::unique_lock< mutex > lk( mtx_);
return get_exception_ptr_( lk);
diff -u -r ./future.hpp ../../../../../support/deps/include/boost/fiber/future/future.hpp
--- ./future.hpp 2015-10-14 19:17:13.169202093 +0200
+++ ../../../../../support/deps/include/boost/fiber/future/future.hpp 2015-10-14 19:26:14.656559563 +0200
@@ -77,7 +77,7 @@
}
ptr_t tmp;
tmp.swap( state_);
- return tmp->get();
+ return tmp->detach();
}
std::exception_ptr get_exception_ptr() {
BTW: there is a reason why this issue is closed? We should continue elsewhere?
from fiber.
please note that boost.fiber is still in development ...
I've pushed a new version to branch develop - futures support moveable-only objects now
from fiber.
Related Issues (20)
- Boost.fiber incompatible with C++20 HOT 1
- Boost.Fiber header compile fails with GCC Compile option -Werror=conversion
- Maybe a semaphore should be added HOT 1
- segment fault when closed buffered_channel on destructor
- build failed with cxxflags -D BOOST_FIBERS_NO_ATOMICS (version 1.80.0)
- Warning/error about unreferenced parameter in context.cpp HOT 2
- std::aligned_storage raises deprecation warning with the latest gcc 13 and C++23 (to be released in about 1 month and a half) HOT 2
- Boost fiber's demo run error when open AddressSanitizer by use Visual Studio HOT 1
- Build script relies on third party to import Context before Fiber
- Weird behavior with custom `algorithm_with_properties<>`
- Memory leak exists when setting custom scheduler algorithm in use_scheduling_algorithm function? HOT 1
- fiber::sleepfor stop updating when system clock moves backwards
- Launching fiber on a different thread HOT 3
- Could not link fiber 1.84.0 as shared library on Windows 10 HOT 4
- Mixing `fiber::mutex` and normal threads HOT 1
- Modular Boost C++ Libraries Request
- use it in qt
- Weird infinite loop when cv.notify_all() HOT 3
- no way to calculate hash of `fiber::id`
- Explicit context switch of fibers
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fiber.