У меня есть программа, которую я только что изменил, используя коллекцию boost :: multi_index_container. После того, как я сделал это и протестировал мой код в режиме отладки, я чувствовал себя довольно хорошо.
Однако затем я скомпилировал сборку релиза с набором NDEBUG, и код потерпел крах. Не сразу, но иногда в однопоточных тестах и часто в многопоточных тестах.
Ошибки сегментации происходят глубоко внутри вставки наддува и функций поворота, связанных с обновлениями индекса, и происходят потому, что узел имеет нулевые левый и правый указатели.
Мой код выглядит примерно так:
struct Implementation {
typedef std::pair<uint32_t, uint32_t> update_pair_type;
struct watch {};
struct update {};
typedef boost::multi_index_container<
update_pair_type,
boost::multi_index::indexed_by<
boost::multi_index::ordered_unique<
boost::multi_index::tag<watch>,
boost::multi_index::member<update_pair_type, uint32_t, &update_pair_type::first>
>,
boost::multi_index::ordered_non_unique<
boost::multi_index::tag<update>,
boost::multi_index::member<update_pair_type, uint32_t, &update_pair_type::second>
>
>
> update_map_type;
typedef std::vector< update_pair_type > update_list_type;
update_map_type update_map;
update_map_type::iterator update_hint;
void register_update(uint32_t watch, uint32_t update);
void do_updates(uint32_t start, uint32_t end);
};
void Implementation::register_update(uint32_t watch, uint32_t update)
{
update_pair_type new_pair( watch_offset, update_offset );
update_hint = update_map.insert(update_hint, new_pair);
if( update_hint->second != update_offset ) {
bool replaced _unused_ = update_map.replace(update_hint, new_pair);
assert(replaced);
}
}