提升继续恢复断言失败
boost continuation resume Assert failed
我尝试测试延续,我的代码如下
ctx::continuation fc1;
ctx::continuation fc2;
ctx::continuation foo1(ctx::continuation&& c) {
LOG_DBUG("enter");
c = c.resume();
LOG_DBUG("done 1");
fc2 = fc2.resume();
LOG_DBUG("done 2");
fc2 = fc2.resume();
return std::move(c);
}
ctx::continuation foo2(ctx::continuation&& c) {
LOG_DBUG("enter");
c = c.resume();
LOG_DBUG("done 1");
fc1 = fc1.resume();
LOG_DBUG("done 2");
fc1 = fc1.resume();
return std::move(c);
}
int main() {
fc1 = ctx::callcc(foo1);
fc2 = ctx::callcc(foo2);
LOG_INFO("after callcc");
for (;;) {
while(fc1 = fc1.resume()) LOG_DBUG("main c1");
while(fc2 = fc2.resume()) LOG_DBUG("main c2");
break;
}
std::cout << "main: done" << std::endl;
return 0;
}
标准输出得到
DBUG [coepoll.cpp:36] [foo1]enter
DBUG [coepoll.cpp:46] [foo2]enter
INFO [coepoll.cpp:61] [main]after callcc
DBUG [coepoll.cpp:38] [foo1]done 1
DBUG [coepoll.cpp:48] [foo2]done 1
./myboost/include/boost/context/continuation_fcontext.hpp:263: boost::context::continuation boost::context::continuation::resume(( &&: 断言 'nullptr != fctx_' 失败。
似乎在函数foo2
调用fc1 = fc1.resume()
导致断言失败。 我的代码中是否有错误?
调用resume
时,continuation
对象失效。
参考资料 说:
延续是一次性延续 - 它只能使用一次, 调用 continuation::resume(( 或 continuation::resume_with(( 之后 已失效。
以下伪代码显示了resume
函数的工作原理:
foo(continutation&& mainContext) {
mainContext = mainContext.resume();
// |
// | [2] resume is called;
// | [2] resume invalidates mainContext;
// | [2] no return value is assigned to mainContext!
// | [2] we go back to main
// [4] |
// make assignment |
// now mainContext |
// is valid |
}
int main(){
fooContext = callcc( foo ); // [1] we enter into foo function;
fooContext = fooContext.resume(); // [3] we go back to foo
}
下面是代码的简化版本,让我们分析一下:
ctx::continuation foo1(ctx::continuation&& main) {
main = main.resume(); // [2]
fc2 = fc2.resume(); // [6]
fc2 = fc2.resume();
return std::move(c);
}
ctx::continuation foo2(ctx::continuation&& main) {
main = main.resume(); // [4]
fc1 = fc1.resume(); // [7]
fc1 = fc1.resume();
return std::move(c);
}
int main() {
fc1 = ctx::callcc(foo1); // [1]
fc2 = ctx::callcc(foo2); // [3]
for (;;) {
while(fc1 = fc1.resume()) LOG_DBUG("main c1"); // [5]
while(fc2 = fc2.resume()) LOG_DBUG("main c2");
break;
}
foo1
开始。- 执行返回到
main
。 foo2
开始。- 执行返回到
main
。 resume
在fc1
上被调用。fc1
无效。控件执行返回到 [6]。- 在恢复
foo2
的这一行执行中,我们跳转到 [7]。 resume
在无效fc1
调用,程序中止。
相关文章:
- 尝试使用 std::vector<std::thread时出现静态断言失败错误>
- uint_not_usable_without_attribute在业力规则中使用数字生成器时静态断言失败
- 从 exe 文件 (Visual Studio ) 启动时调试断言失败
- 在 CppUnit 中测试中止断言失败
- 使用扫描的调试断言失败
- 为什么我的Qt程序在断言失败后继续运行?
- 图片不显示,关闭时出错 --> 调试断言失败!表达式:is_block_type_valid(标头>_block_use)
- 访问提升:shared_ptr 主范围外崩溃,断言失败:px != 0.指针的正确用法是什么?
- C++ 调试断言失败 - 矢量下标超出视觉工作室的范围
- 错误:断言失败 (src.type() == CV_8UC1) 在阈值中
- Boost Beast 异步服务器失败,断言失败:(id_ != T::id) 在多个 aync 调用中
- 使用imwrite OpenCV时断言失败
- 调试断言失败的缓冲区!=nullptr
- 使用 ofstream 写入文本文件时断言失败
- 提升继续恢复断言失败
- 获取有关调试断言失败的错误:表达式:"(_Ptr_user &(_BIG_ALLOCATION_ALIGNMENT -1)) == 0" &&0
- OpenCV(3.4.1) 错误:断言失败(变暗 <= 2 && step[0] > 0) in cv::Mat::locateROI
- 在Win10上使用带有Qt5的OpenCV3.0,调试断言失败
- MFC GetDC() 断言失败 - "Not a window"
- OpenCV 错误:断言失败 - 矩阵减去