Modify

Ticket #6277 (closed Bugs: fixed)

Opened 5 years ago

Last modified 4 months ago

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

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

Change History

Changed 5 years ago by internet@…

Code which demonstrates the bug

comment:1 follow-up: ↓ 2 Changed 4 years ago by viboes

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

comment:2 in reply to: ↑ 1 Changed 4 years ago by anonymous

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 Changed 3 years ago by viboes

  • Owner changed from jano_gaspar to viboes
  • Status changed from new to assigned

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 3 years ago by viboes (previous) (diff)

comment:4 follow-up: ↓ 5 Changed 3 years ago by viboes

  • Severity changed from Showstopper to Problem

As there is a workaround this is not a Showstopper.

comment:5 in reply to: ↑ 4 Changed 10 months ago by ronan.keryell@…

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 follow-up: ↓ 7 Changed 7 months ago by andysem

comment:7 in reply to: ↑ 6 Changed 7 months ago by ronan.keryell@…

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 Changed 4 months ago by andysem

  • Status changed from assigned to closed
  • Resolution set to fixed
View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.