Opened 11 years ago

Closed 6 years ago

#6277 closed Bugs (fixed)

Checked iterators are not threadsafe

Reported by: internet@… Owned by: viboes
Milestone: To Be Determined Component: circular_buffer
Version: Boost 1.46.1 Severity: Problem
Keywords: Cc:

Description

I encountered a problem whereby I was using the copy constructor of boost::circular_buffer in multiple threads. The attached code demonstrates the problem. The problem appears to be caused by the checked iterators, so does not occur in release builds.

Actual behaviour: Segmentation fault.

Expected behaviour: Program should loop indefinitely.

Workaround: #define BOOST_CB_DISABLE_DEBUG

Compilers tested: g++ 4.6.1 Visual C++ 2010 (cl.exe 16.00)

Platforms tested: x86_64-linux-gnu (Ubuntu 11.04) Windows 7 x64

Boost versions tested: Linux 1.46.1.1 (Ubuntu) Linux 1.48.0 Windows 1.46.1

Attachments (1)

cb.cpp (610 bytes ) - added by internet@… 11 years ago.
Code which demonstrates the bug

Download all attachments as: .zip

Change History (9)

by internet@…, 11 years ago

Attachment: cb.cpp added

Code which demonstrates the bug

comment:1 by viboes, 9 years ago

No library is thread-safe until it is stated explicitly. Where this is on the documentation?

in reply to:  1 comment:2 by anonymous, 9 years ago

Replying to viboes:

No library is thread-safe until it is stated explicitly. Where this is on the documentation?

Here: http://www.boost.org/doc/libs/1_53_0/libs/circular_buffer/doc/circular_buffer.html#threadsafety

"simultaneous read accesses to a shared circular_buffer are safe."

This is also a requirement for C++11.

comment:3 by viboes, 9 years ago

Owner: changed from Jan Gaspar to viboes
Status: newassigned

Oh thanks for clarification. What do you think of removing this specific debug behavior?

// BOOST_CB_ENABLE_DEBUG: Debug support control.
#if defined(NDEBUG) || defined(BOOST_CB_DISABLE_DEBUG)
    #define BOOST_CB_ENABLE_DEBUG 0
#else
    #define BOOST_CB_ENABLE_DEBUG 1
#endif
// Debug enable is disabled temporarily as the associated code is not thread safe?
#undef BOOST_CB_ENABLE_DEBUG
Last edited 9 years ago by viboes (previous) (diff)

comment:4 by viboes, 9 years ago

Severity: ShowstopperProblem

As there is a workaround this is not a Showstopper.

in reply to:  4 comment:5 by ronan.keryell@…, 7 years ago

Replying to viboes:

As there is a workaround this is not a Showstopper.

Recently I spent more than a week chasing some bugs that ended up to be in this racy debug code of Boost Circular Buffer...

So at least if it is not considered as a show-stopper, the issue and the work-around should be explained in the documentation in sections "Thread-Safety" and "Debug Support" of http://www.boost.org/doc/libs/1_60_0/doc/html/circular_buffer/implementation.html

Besides this, this library is great! Thanks.

comment:6 by Andrey Semashev, 6 years ago

in reply to:  6 comment:7 by ronan.keryell@…, 6 years ago

Replying to andysem:

I've created a PR to fix this: https://github.com/boostorg/circular_buffer/pull/9.

Nice! I've tried your version in https://github.com/amd/triSYCL/commit/dd5adeb9d8954ebccf13b837e5a6d415752db490 and it works. So, for me, it looks ready to land.

Thank you for your fix of this 4 year old bug!

comment:8 by Andrey Semashev, 6 years ago

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.