[英]“map/set iterators incompatible” while calling std::map::find
C++ 0x11 (sort of. You know, Microsoft, and all...), Visual Studio 2010 SP1, Windows 7 Enterprise. C ++ 0x11(包括Microsoft和所有...),Visual Studio 2010 SP1,Windows 7 Enterprise。
I've got a function: 我有一个功能:
// typedef boost::variant</*stuff*/> value_t;
// typedef unsigned short key_t
// typedef std::map<key_t, value_t> map_t
value_t find(const key_t key, const map_t &map)
{
const map_t::const_iterator iter(map.find(key));
// ...More stuff and then return.
}
Within the body of std::map::find, there is an iterator comparison, and I'm getting the error message "map/set iterators incompatible", as defined in VC\\include\\xtree:321. 在std :: map :: find的正文中,有一个迭代器比较,并且我得到了错误消息“ map / set迭代器不兼容”,如VC \\ include \\ xtree:321中所定义。 The nature of this error is that iterators from two different containers are being compared to one another, but the error is coming from within a containers own find function!!!
此错误的性质是,正在将来自两个不同容器的迭代器相互比较,但该错误来自容器自身的find函数内部! Retorically, where could another container's iterator be coming from.
反过来,另一个容器的迭代器可能来自哪里。
Ok, symptoms: 好的,症状:
My questions to the greater community: 我对广大社区的提问:
Supposing this is a timing error in a threaded environment, can a change to the internal state of the map, mid way through this process, modify what would be the value of template class _Tree_const_iterator::_Getcont()? 假设这是线程环境中的计时错误,可以在此过程的中途更改映射的内部状态,修改模板类_Tree_const_iterator :: _ Getcont()的值吗? I'm supposing the map is being cleared and repopulated in another thread before the find in this thread completes.
我假设在此线程中的查找完成之前,正在另一个线程中清除并重新填充地图。 Could that alone do it?
单单能做到吗? Or how about a swap or move operation?
或交换或移动操作如何?
I'll track down the missing mutex lock or whatever, I just want to make sure I understand all the plausible means I can enter this state, given this context. 我将查找丢失的互斥锁或其他任何内容,我只想确保自己了解在给定上下文的情况下可以进入此状态的所有可行方法。
Supposing this is a timing error in a threaded environment
假设这是线程环境中的计时错误
Then all bets are off. 然后所有赌注都关闭了。 If your code is threaded and isn't thread safe, then you can get all kinds of errors.
如果您的代码是线程化的,并且不是线程安全的,那么您会遇到各种错误。
std::map
is not thread-safe (you can't access it while it's being modified), so you could get plenty of kinds of errors. std::map
不是线程安全的(修改后无法访问它),因此您可能会遇到很多错误。
Make sure your code is thread safe before assuming something else is wrong. 在假定其他错误之前,请确保您的代码是线程安全的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.