rigtorp / MPMCQueue

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

Resolve construction core dump #39

Closed g302ge closed 10 months ago

g302ge commented 11 months ago

if some class constructor cause some nullptr exception caused core dump. How to resolve this at

https://github.com/rigtorp/MPMCQueue/blob/28d05c021d68fc5280b593329d1982ed02f9d7b3/include/rigtorp/MPMCQueue.h#L173

rigtorp commented 11 months ago

Constructors must be noexcept: static_assert(std::is_nothrow_constructible<T, Args &&...>::value, "T must be nothrow constructible with Args&&...");

On Thu, Aug 3, 2023 at 11:43 AM George @.***> wrote:

if some class constructor cause some nullptr exception caused core dump. How to resolve this at

https://github.com/rigtorp/MPMCQueue/blob/28d05c021d68fc5280b593329d1982ed02f9d7b3/include/rigtorp/MPMCQueue.h#L173

— Reply to this email directly, view it on GitHub https://github.com/rigtorp/MPMCQueue/issues/39, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABLO27IX67HQ7TJNNACJM3XTPILFANCNFSM6AAAAAA3DBPG4E . You are receiving this because you are subscribed to this thread.Message ID: @.***>

g302ge commented 10 months ago

Thx for your reply. But in my view, the constructor must not be noexcept is a very strong safety for the lock free situation. In other words the constructor or some code in the critical section like constructor in this case should be more atomic as they can do. if this view is correct ?

rigtorp commented 10 months ago

There is no way to unwind a partial enqueue operation unfortunately. This means that constructing the enqeued time cannot fail.

The solution is to mark failed enques and skip them, I didn't want everyone to pay the cost of this by default. What you can do is create a wrapper type: template struct nothrow_wrapper { T v; bool valid;

nothrow_wrapper(T &&v) { try { this->v = v; valid=true; catch (...) { valid=false; } } }

And then check for valid items when you pop();

However it should always be possible to create a noexcept move constructor.

On Wed, Aug 30, 2023 at 2:39 PM George @.***> wrote:

Thx for your reply. But in my view, the constructor must not be noexcept is a very strong safety for the lock free situation. In other words the constructor or some code in the critical section like constructor in this case should be more atomic as they can do. if this view is correct ?

— Reply to this email directly, view it on GitHub https://github.com/rigtorp/MPMCQueue/issues/39#issuecomment-1699732726, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABLO2YOZTEWKOTHE4NMPC3XX6JHVANCNFSM6AAAAAA3DBPG4E . You are receiving this because you commented.Message ID: @.***>

g302ge commented 10 months ago

thx for your reply , I have fix my variant version in a safe situation