|
Boost : |
From: Murali Kishore (bmuralikishore_at_[hidden])
Date: 2024-09-09 13:18:18
Hi all,
I see multiset is not present in boost interprocess, so I tried to use a
"set" with a customized comparator to achieve multiset functionality.
sample code:
struct set_comparator
{
bool operator()(const int& a, const int& b) const
{
return a < b; // if change a <= b then seeing an errror
}
};
bip::shared_memory_object::remove("SHM");
bip::managed_shared_memory segment(bip::open_or_create, "SHM",
2047*1024*1024);
typedef bip::allocator<int, bip::managed_shared_memory::segment_manager>
ShmemAllocator;
typedef bip::set<int, set_comparator, ShmemAllocator> ShmemSet;
segment.destroy<ShmemSet>("MySet");
ShmemSet *sample1 = segment.construct<ShmemSet>("MySet")(set_comparator(),
segment.get_segment_manager());
std::cout << "Insert in shared set:" << std::endl;
sample1->insert(40);
std::cout << "Insert in shared set:" << std::endl;
sample1->insert(40); // Crashing here
sample1->insert(40);
sample1->insert(40);
sample1->insert(20);
sample1->insert(20);
sample1->insert(20);
sample1->insert(20);
sample1->insert(20);
when i try duplicate insertion, seeing following error,
/usr/include/boost/intrusive/bstree.hpp:1331:
boost::intrusive::bstree_impl<ValueTraits, VoidOrKeyOfValue, VoidOrKeyComp,
SizeType, ConstantTimeSize, AlgoType, HeaderHolder>::iterator
boost::intrusive::bstree_impl<ValueTraits, VoidOrKeyOfValue, VoidOrKeyComp,
SizeType, ConstantTimeSize, AlgoType,
HeaderHolder>::insert_unique_commit(boost::intrusive::bstree_impl<ValueTraits,
VoidOrKeyOfValue, VoidOrKeyComp, SizeType, ConstantTimeSize, AlgoType,
HeaderHolder>::reference, const insert_commit_data&) [with ValueTraits =
boost::intrusive::bhtraits<boost::container::dtl::tree_node<int,
boost::interprocess::offset_ptr<void>, boost::container::red_black_tree,
true>,
boost::intrusive::rbtree_node_traits<boost::interprocess::offset_ptr<void>,
true>, boost::intrusive::normal_link, boost::intrusive::dft_tag, 3>;
VoidOrKeyOfValue = void; VoidOrKeyComp =
boost::container::value_to_node_compare<boost::container::dtl::tree_node<int,
boost::interprocess::offset_ptr<void>, boost::container::red_black_tree,
true>,
boost::intrusive::tree_value_compare<boost::interprocess::offset_ptr<int,
long int, long unsigned int, 0>, main()::set_comparator,
boost::move_detail::identity<int>, bool, true>, bool>; SizeType = long
unsigned int; bool ConstantTimeSize = true; boost::intrusive::algo_types
AlgoType = boost::intrusive::RbTreeAlgorithms; HeaderHolder = void;
boost::intrusive::bstree_impl<ValueTraits, VoidOrKeyOfValue, VoidOrKeyComp,
SizeType, ConstantTimeSize, AlgoType, HeaderHolder>::iterator =
boost::intrusive::tree_iterator<boost::intrusive::bhtraits<boost::container::dtl::tree_node<int,
boost::interprocess::offset_ptr<void>, boost::container::red_black_tree,
true>,
boost::intrusive::rbtree_node_traits<boost::interprocess::offset_ptr<void>,
true>, boost::intrusive::normal_link, boost::intrusive::dft_tag, 3>,
false>; boost::intrusive::bstree_impl<ValueTraits, VoidOrKeyOfValue,
VoidOrKeyComp, SizeType, ConstantTimeSize, AlgoType,
HeaderHolder>::reference = boost::container::dtl::tree_node<int,
boost::interprocess::offset_ptr<void>, boost::container::red_black_tree,
true>&; boost::intrusive::bstree_impl<ValueTraits, VoidOrKeyOfValue,
VoidOrKeyComp, SizeType, ConstantTimeSize, AlgoType,
HeaderHolder>::insert_commit_data =
boost::intrusive::insert_commit_data_t<boost::interprocess::offset_ptr<boost::intrusive::compact_rbtree_node<boost::interprocess::offset_ptr<void>
>, long int, long unsigned int, 0> >]: Assertion `( p == this->end() ||
!this->comp()(*p, value) )' failed.
"Need input on this or is this expected behaviour as per boost??"
-- Regards, Murali Kishore
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk