#include
#include
#include
template class skein {
public:
using value_type = T;
using ptr_type = std::shared_ptr;
virtual ~skein() = default;
skein()
: m_future(boost::fibers::async(
std::bind(&skein::func_p, this))) {};
skein(const skein &) = delete;
skein(skein &&) = delete;
void wait() { m_future.wait(); };
ptr_type get_ptr() {
wait();
return m_future.get();
};
value_type *get() { return get_ptr().get(); }
boost::fibers::future m_future;
protected:
virtual value_type func() = 0;
ptr_type func_p() { return std::make_shared(func()); }
};
Я использую это с помощью main.cpp , определяемое как следующее:
Код: Выделить всё
#include
#include
class echo_int : public skein {
public:
echo_int(int value) : skein(), m_value(value) {};
protected:
const int m_value;
virtual int func() { return m_value; };
};
auto main() -> int {
auto sk = new echo_int(5);
// this should work
auto ivv = sk->m_future.get();
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79658065/using-a-future-from-boost-fiber-why-is-my-code-accessing-an-uninitialized-futur[/url]
Мобильная версия