【发布时间】:2014-08-22 04:24:23
【问题描述】:
我正在使用Boost coroutine library,我需要我的协程可重入。
这意味着我应该能够从头开始多次启动协程。
有哪些选择?
我目前的解决方法是每次都重新创建新的协程:
boost::coroutines::coroutine<int>::pull_type *source = new boost::coroutines::coroutine<int>::pull_type(
[&](boost::coroutines::coroutine<int>::push_type& sink){
sink(0);
cout << "Hello world!" << endl;
});
(*source)();
source = new boost::coroutines::coroutine<int>::pull_type(
[&](boost::coroutines::coroutine<int>::push_type& sink){
sink(0);
cout << "Hello world!" << endl;
});
(*source)();
source = new boost::coroutines::coroutine<int>::pull_type(
[&](boost::coroutines::coroutine<int>::push_type& sink){
sink(0);
cout << "Hello world!" << endl;
});
(*source)();
【问题讨论】:
-
泄漏怎么办?
-
@Manu343726
delete为清楚起见未显示调用