Boost logo

Boost :

From: Achilleas Margaritis (axilmar_at_[hidden])
Date: 2007-12-01 19:43:00

Isn't there a deadlock issue with futures? suppose I have the following

class A {
     int data;

     int getData() const {
         return data;

     void someAction(B *b) {
         future<int> i = bind(b, &B::someAction, this);
         data = i.wait() + 1;

class B {
     int data;

     int someAction(A *a) {
         future<int> j = bind(a, &A::getData);
         return j.wait() + 1;

int main() {
      A *a = new A;
      B *b = new B;

The above contains a deadlock:

class A builds a future 'i' in function 'someAction' over class B, then
it waits for B's method 'someAction' to wait.

class B, when its method 'someAction' is invoked, builds a future 'j'
over method 'getData' of A...then it tries to evaluate 'j'.

At this point, the instance of A is blocked waiting for B to finish its
processing, and B waits for A to finish its processing, thus deadlocking
the program.

My question is: is this a real problem, and if so, how is it handled by

Another way to introduce the deadlock is by mutual recursion using futures.

Boost list run by bdawes at, gregod at, cpdaniel at, john at