rigtorp / MPMCQueue

A bounded multi-producer multi-consumer concurrent queue written in C++11
MIT License
1.18k stars 160 forks source link

Memory corruption issue with slot storage #1

Closed lafp02 closed 8 years ago

lafp02 commented 8 years ago

Hi,

I ported the code to MS Visual Studion 2015 and while storing large structures, I found that the slot storage as declared below was buggy (or not portable).

std::aligned_storage<sizeof(T), alignof(T)> storage;

I fixed it by declaring as:

typename std::aligned_storage<sizeof(T), alignof(T)>::type storage;

sizeof(std::aligned_storage<sizeof(T), alignof(T)>) is "1" sizeof(std::aligned_storage<sizeof(T), alignof(T)>::type) was the proper size of my type "T".

I suspect that the type you tested were small enough to fit in the "padding" to prevent false sharing.

rigtorp commented 8 years ago

Thanks for reporting!