不可能的事件序列 [英] Impossible sequence of events

查看:115
本文介绍了不可能的事件序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在中跟踪一个神秘的迭代器问题,用于循环。我在迭代器的 operator!= 中得到一个错误,这通常意味着被比较的迭代器不属于同一个容器。跟踪到Microsoft的库的实现 operator!= 调用 operator == 其中此测试为true:

I'm trying to track down a mysterious iterator problem in a for loop. I get an error in the iterator's operator!= which generally means that the iterators being compared do not belong to the same container. Tracing into Microsoft's implementation of the library, operator!= calls operator== where this test is true:

    bool operator==(const _Myiter& _Right) const
        {   // test for iterator equality
 #if _ITERATOR_DEBUG_LEVEL == 2
        if (this->_Getcont() == 0
            || this->_Getcont() != _Right._Getcont())
            {   // report error
            _DEBUG_ERROR("list iterators incompatible");

为了获得更多信息,我写了这个小函数来替换我的中为循环指定

In an attempt to get more information I wrote this little function to replace my != in the for loop:

template<typename iter>
bool bang_equal(const iter & left, const iter & right)
{
   static int count = 0;
   auto p1 = left._Getcont();
   auto p2 = right._Getcont();
   ATLTRACE("Iterator comparison left _Getcont()=%p right _Getcont()=%p %d\n", p1, p2, ++count);
   MemoryBarrier();
   bool b = left != right;
   MemoryBarrier();
   auto p3 = left._Getcont();
   auto p4 = right._Getcont();
   ATLTRACE("                    left _Getcont()=%p right _Getcont()=%p %d\n", p3, p4, ++count);
   return b;
}

这里是有趣的地方。我仍然得到表达式 left!= right 中的错误,调试器停在那里,但是第一个 ATLTRACE 被跳过或第二个提前运行!调试器输出有两行,调试器显示的 count 的值与输出的最后一行匹配。

Here's where it gets interesting. I still get the error in the expression left != right and the debugger stops there, but either the first ATLTRACE has been skipped or the second one has run ahead of time! The debugger output has both lines, and the value of count as shown by the debugger matches the last line of output.

Iterator comparison left _Getcont()=07D0B2C8 right _Getcont()=07D0B2C8 2984
                    left _Getcont()=07D0B2C8 right _Getcont()=07D0B2C8 2985
Myprog.exe has triggered a breakpoint.

查看反汇编窗口显示预期顺序中的说明。我被骗了。可能发生什么?

Looking at the disassembly window shows the instructions in the expected order. I'm stumped. What might be happening?

推荐答案

最后弄清楚了。 Microsoft函数 _Debug_message 显示一个对话框,询问是否要中止,重试(调试)或忽略错误。显示对话框时,消息泵仍在运行,允许进行其他活动。我的功能被再次调用,这次它运行完成,在过程中产生大量的调试输出。如果我在库代码中的 _DEBUG_ERROR 行放置一个明确的断点,我捕获错误,没有额外的执行在后台。回想一下调试输出有益于事后我可以看到预期的错误输出确实存在,只是埋没到目前为止,我从来没有看到它。

Finally figured it out. The Microsoft function _Debug_message displays a dialog box asking if you want to Abort, Retry (debug), or Ignore the error. While the dialog box is displayed the message pump is still running, allowing other activity to take place. My function was being called again and this time it ran to completion, generating lots of debug output in the process. If I put an explicit breakpoint on the _DEBUG_ERROR line in the library code I catch the error without additional execution in the background. Looking back at the debug output with the benefit of hindsight I can see that the expected error output was indeed there, just buried so far that I never saw it.

这篇关于不可能的事件序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆