Modify

Opened 6 years ago

Closed 11 months 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@… 6 years ago.
Code which demonstrates the bug

Download all attachments as: .zip

Change History (9)

Changed 6 years ago by internet@…

Code which demonstrates the bug

comment:1 follow-up: 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 4 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 4 years ago by viboes (previous) (diff)

comment:4 follow-up: Changed 4 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 17 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: Changed 14 months ago by andysem

comment:7 in reply to: ↑ 6 Changed 14 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 11 months ago by andysem

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

Add Comment

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain viboes.
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.