Boost logo

Boost Users :

Subject: [Boost-users] [Fiber] Can a fiber promise be set in a different OS thread on which has no fibers running
From: lin li (sdeber_at_[hidden])
Date: 2017-05-11 06:51:36

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 <boost/date_time/posix_time/posix_time_duration.hpp>
#include <boost/thread/pthread/mutex.hpp>
#include <boost/thread/lock_guard.hpp>
#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);


void setf()
  // Is it safe to do this?

void f1()
    boost::fibers::fiber fiberJob(&setf);

int main(int argc, char** argv)

    boost::thread t(&f);
    cout << "Here" << endl;
    cout << "Here 2" << endl;
    return 0;

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at