Boost logo

Boost :

Subject: Re: [boost] [Review.Coroutine] Lifetime of coroutine parameters
From: Vicente Botet (vicente.botet_at_[hidden])
Date: 2012-09-11 06:07:34


Oliver Kowalke wrote
>
>> Surprisingly (well not really), the following example doesn't fails at
>> *1*. This is because the coroutine have access to its coroutine
>> parameters *2*, which has a sens only for the first time the coroutine
>> is called.
>
> your exchange addresses between main() and coroutine-fn (lifetime()).
> you could use it also a second time etc. as long as the object does not go
> out of scope.
>
>> Once the first call to yield return, the memory these
>> parameter *3* can point to trash, as the example shows.
>
> sorry - that is not an issue of boost.coroutine itself.
>
> Who would store pointers/references to objects and expects that those
> objects can still be accessed over the pointers/references after those
> objects were destroyed. But that is the case in your example.
>
> Your example in issue *3* is equivalent to storing an reference as member
> in some class and access the member after the original object was gone out
> of scope.
>
> struct X
> { void g() {} };
>
> struct Y
> {
> X & x;
> Y( X & x_) : x( x_) {}
> void f() { x.g(); }
> };
>
> Y u()
> {
> X x;
> Y y( x);
> y.f(); // OK
> }
>
> void main()
> {
> Y y( u() );
> y.f(); // segfault
> }
>

Yes, this is similar, except that the current Coroutine interface is giving
access to the user to an invalid address to easily. The user has just to use
the coroutine parameter.

I don't know if you will find a solution, but I expect at least that you
will mention it on the documentation with a big warning.

Best,
Vicente

--
View this message in context: http://boost.2283326.n4.nabble.com/Review-Coroutine-Lifetime-of-coroutine-parameters-tp4635553p4635587.html
Sent from the Boost - Dev mailing list archive at Nabble.com.

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