So I did myself a small program. It seems to prove that this is working correctly in the case I asked, but I still cannot figure out why it does strange things in other code I have.
#include <boost/coroutine/all.hpp>
using namespace boost::coroutines;
int * g_i = nullptr;
coroutine<void>::pull_type
my_func() {
coroutine<void>::pull_type coro(
[](coroutine<void>::push_type & suspend_coro) {
int i = 7;
g_i = &i;
suspend_coro();
++i;
g_i = &i;
suspend_coro();
});
return coro;
}
int main(int argc, char * argv[]) {
auto coro = my_func();
std::cout << *g_i << std::endl;
coro();
std::cout << *g_i << std::endl;
}
Prints 7 and 8.