Constructing vector of POD using boost interprocess throws exception only in debug mode
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- cpp
- Domain
- operating-systems
Research direction
Reproduce the sample in debug mode, focusing on the boost::container vector construction and resize of queue_pool. Inspect the assertion at boost/interprocess/mem_algo/rbtree_best_fit.hpp:698 and the allocator path for Ringbuffer<65536>. Done means explaining the alignment failure and confirming corrected behavior in both debug and release builds.
Written by the indexing model from the issue text.
Description
I am trying to construct a bip::vector of POD using boost interprocess managed shared memory. The following code compiles and run in release mode, but crashes in debug mode.
#include <cstdint>
#include <boost/interprocess/allocators/allocator.hpp>
#include <boost/interprocess/containers/string.hpp>
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/container/vector.hpp>
#include <iostream>
// Forward declaration of Ringbuffer<65536>
template <uint32_t Bytes>
class Ringbuffer;
namespace shared {
namespace bipc = boost::interprocess;
using Segment = bipc::managed_shared_memory;
using Manager = Segment::segment_manager;
template <typename T>
using Alloc = bipc::allocator<T, Manager>;
template <typename T>
using Vector = boost::container::vector<T, Alloc<T>>;
} // namespace shared
using MsgQueue = Ringbuffer<65536>;
using msg_queue_pool_t = shared::Vector<MsgQueue>;
template <uint32_t Bytes>
class Ringbuffer {
public:
struct MsgHeader {
uint32_t size;
uint32_t userdata;
};
private:
struct Block {
alignas(64) MsgHeader header;
};
static constexpr uint32_t BLK_CNT = Bytes / sizeof(Block);
static_assert(BLK_CNT && !(BLK_CNT & (BLK_CNT - 1)), "BLK_CNT must be a power of 2");
Block blk[BLK_CNT];
alignas(64) uint64_t written_idx{0};
alignas(64) uint64_t last_key_idx{0};
alignas(64) uint64_t writing_idx{0};
alignas(64) bool in_use{false};
};
int main(int argc, char** argv) {
auto segment_ptr =
std::make_unique<boost::interprocess::managed_shared_memory>(boost::interprocess::create_only, "ShareMemory", 65536 * 20);
msg_queue_pool_t* ringbuffer_pool =
segment_ptr->construct<msg_queue_pool_t>("queue_pool")(5, segment_ptr->get_segment_manager());
ringbuffer_pool->resize(10);
std::cout << "hello world!" << std::endl;
return 0;
}
The error when running in debug mode:
boost_interprocess_issue: /home/rnd/.xmake/packages/b/boost/1.81.0/9a76068f70604ea18becd4a3064bdac1/include/boost/interprocess/mem_algo/rbtree_best_fit.hpp:698: T* boost::interprocess::rbtree_best_fit<MutexFamily, VoidMutex, MemAlignment>::allocation_command(boost::container::allocation_type, boost::interprocess::rbtree_best_fit<MutexFamily, VoidMutex, MemAlignment>::size_type, boost::interprocess::rbtree_best_fit<MutexFamily, VoidMutex, MemAlignment>::size_type&, T*&) [with T = Ringbuffer<65536>; MutexFamily = boost::interprocess::mutex_family; VoidPointer = boost::interprocess::offset_ptr; long unsigned int MemAlignment = 0; boost::container::allocation_type = unsigned int; boost::interprocess::rbtree_best_fit<MutexFamily, VoidMutex, MemAlignment>::size_type = long unsigned int]: Assertion `0 == ((std::size_t)ret % ::boost::container::dtl::alignment_of::value)' failed.
how could I fix the issue?
- Dominant language
- C++
- Stars
- 185
- Forks
- 131
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from boostorg/interprocess
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
boostorg/interprocess#196 · 1 reaction ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
boostorg/interprocess#279 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
boostorg/interprocess#274 · 1 comment ·
-
Difficulty 5/5 Over a week Newbie friendliness 28/100
boostorg/interprocess#268 · 4 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
boostorg/interprocess#262 · 2 comments ·
All issues in boostorg/interprocess
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
AXERA-TECH/ax-llm#77 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
games-on-whales/wolf#509 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
bug-unconfirmed
Difficulty 2/5 1-3 hours Newbie friendliness 76/100