boostorg / boostorg/interprocess

Constructing vector of POD using boost interprocess throws exception only in debug mode

Abierto
#208 1 comentario 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
C++
Estrellas
185
Forks
131
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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
#include
#include
#include
#include
#include

// Forward declaration of Ringbuffer<65536>
template
class Ringbuffer;

namespace shared {
namespace bipc = boost::interprocess;
using Segment = bipc::managed_shared_memory;
using Manager = Segment::segment_manager;

template
using Alloc = bipc::allocator;

template
using Vector = boost::container::vector>;
} // namespace shared

using MsgQueue = Ringbuffer<65536>;

using msg_queue_pool_t = shared::Vector;

template
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::create_only, "ShareMemory", 65536 * 20);

msg_queue_pool_t* ringbuffer_pool =
segment_ptr->construct("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::allocation_command(boost::container::allocation_type, boost::interprocess::rbtree_best_fit::size_type, boost::interprocess::rbtree_best_fit::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::size_type = long unsigned int]: Assertion `0 == ((std::size_t)ret % ::boost::container::dtl::alignment_of::value)' failed.
```

how could I fix the issue?

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Reproduce el ejemplo en modo debug, centrándote en la construcción y el resize del vector de boost::container de queue_pool. Inspecciona la aserción en boost/interprocess/mem_algo/rbtree_best_fit.hpp:698 y la ruta del allocator para Ringbuffer<65536>. Se considera terminado cuando se explique el fallo de alineación y se confirme el comportamiento corregido tanto en compilaciones debug como release.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
cpp
Área
operating-systems
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.