Boost logo

Boost :

Subject: Re: [boost] {Review] Coroutine reviewstarts today, September 3rd
From: Oliver Kowalke (oliver.kowalke_at_[hidden])
Date: 2012-09-11 02:13:59


>
> Another issue that I see is with reference/pointer types. The fact
> that the following code will blow up is troubling:
>
> struct X {...};
> typedef boost::coro::generator<X*> gen_t;
>
> void foo(gen_t::self_t& self) {
> X x1, x2;
> self.yield(&x1);
> self.yield(&x2);
> }
>
> gen_t g(foo);
> while( g ) {
> X* val = g();
> // use *val. Ok on first iteration, dangling pointer on the second!!!
> }

X * val is an address of x1/x2 on the stack of foo(). no danglingpointer until coroutine is alive.

> An alternative approach could be to try to make generator itself into
> an input iterator (like Giovanni's design) but that is hard because
> generator is non-copyable.

I've to think about it.

Oliver


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