Boost logo

Boost :

Subject: Re: [boost] {Review] Coroutine reviewstarts today, September 3rd
From: Eugene Yakubovich (eyakubovich_at_[hidden])
Date: 2012-09-11 11:05:54


>> Another issue that I see is with reference/pointer types. The fact
>> that the following code will blow up is troubling:
>>
[snip]
>
> X * val is an address of x1/x2 on the stack of foo(). no danglingpointer until coroutine is alive.
>

Yes, the address would still be valid (stack is not gone) but the
object would have already been destroyed. Maybe a better example:

struct X {
    ~X() { std::cout << "~X" << std::endl; }
};

typedef boost::coro::generator< X* > gen_t;

void foo(gen_t::self_t& self) {
    X x1, x2;
    self.yield(&x1);
    self.yield(&x2);
}

int main() {
    gen_t g(foo);
    while( g ) {
        X* val = g();
        std::cout << "use val" << std::endl;
    }

    return 0;
}

Outputs (ran against the coroutine branch):

use val
~X
~X
use val

Clearly the use of x2 occurs after its destruction.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk