|
Boost : |
Subject: Re: [boost] {Review] Coroutine reviewstarts today, September 3rd
From: Oliver Kowalke (oliver.kowalke_at_[hidden])
Date: 2012-09-11 11:43:21
Am 11.09.2012 17:05, schrieb Eugene Yakubovich:
>> 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
>
Well - what should I do to prevent this? I think I can't. This is an
issue not only related to boost.coroutine you can always construct such
failures with pointers/references.
(remember my example of dereferencing an reference, stored as member in
a class.)
Oliver
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk