I have tested the following example code with Boost 1.61. And it worked (ignore the potential race conditions when accessing the variable 'p'). But I am not sure the fiber promise can be used in this way or I am just being lucky.
#include <cstdlib>
#include "boost/fiber/fiber.hpp"
#include "boost/fiber/future.hpp"
#include "boost/thread.hpp"
#include <set>
#include <iostream>
#include
#include
#include
#include "boost/thread/pthread/thread_data.hpp"
#include "boost/chrono/duration.hpp"
using namespace std;
boost::fibers::promise<int>* p;
void wait()
{
p = new boost::fibers::promise<int>;
auto future = p->get_future();
auto status = future.wait();
std::cout << "Value: " << future.get() << std::endl;
delete p;
}
void f()
{
boost::fibers::fiber fiberJob(&wait);
fiberJob.join();
}
void setf()
{
// Is it safe to do this?
boost::this_thread::sleep(boost::posix_time::seconds(5));
p->set_value(20);
}
void f1()
{
boost::fibers::fiber fiberJob(&setf);
fiberJob.join();
}
int main(int argc, char** argv)
{
boost::thread t(&f);
setf();
cout << "Here" << endl;
t.join();
cout << "Here 2" << endl;
return 0;
}