Modify

Ticket #7875 (closed Bugs: fixed)

Opened 15 months ago

Last modified 15 months ago

BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED should not be enabled by default

Reported by: Andrew Molyneux <andrew.molyneux@…> Owned by: viboes
Milestone: Boost 1.53.0 Component: thread
Version: Boost 1.52.0 Severity: Problem
Keywords: Cc:

Description

I just upgraded to Boost 1.52 on Windows using pre-built binaries and encountered a problem. Because BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED is enabled by default, any code that uses thread::join() will throw an exception if the target thread has already finished executing. Fortunately this was picked up by our unit tests, but the new behaviour could lead to intermittent race condition bugs that could be difficult to track down.

I've attached a patch (to be applied in libs/thread/build) which comments out the BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED defines in the jamfile. Failing that, could someone please explain to me why this feature is enabled by default? It seems like a recipe for disaster. For example, the fix for ticket #7668, which is attempting to work around a bug introduced by this feature, seems to introduce a race condition.

Attachments

Jamfile.v2.patch Download (1001 bytes) - added by Andrew Molyneux <andrew.molyneux@…> 15 months ago.
Stop enabling BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED by default

Change History

Changed 15 months ago by Andrew Molyneux <andrew.molyneux@…>

Stop enabling BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED by default

comment:1 Changed 15 months ago by viboes

Yes, this is abug on 1.52. Version 1.53 lets all (almost all) the uses of BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED on the header files

E.g. the thread::join function is defined on boost/detail/thread.hpp as follows

    void thread::join() {
        if (this_thread::get_id() == get_id())
          boost::throw_exception(thread_resource_error(system::errc::resource_deadlock_would_occur, "boost thread: trying joining itself"));

        BOOST_THREAD_VERIFY_PRECONDITION( join_noexcept(),
            thread_resource_error(system::errc::invalid_argument, "boost thread: thread not joinable")
        );
    }

I will however comment the Jamfile.v2 line

<define>BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED

comment:2 Changed 15 months ago by viboes

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

comment:3 Changed 15 months ago by Andrew Molyneux <andrew.molyneux@…>

Thanks for the quick response Vicente! Glad to hear you're planning to change it. Have you looked at #7668 yet? I'm not sure if Trac notifies you when comments are added to a closed ticket, but I'm pretty sure your fix to thread_group::join_all() has a race condition.

comment:4 Changed 15 months ago by viboes

  • Milestone changed from To Be Determined to Boost 1.53.0

Changeset [82436] by viboes

comment:5 Changed 15 months ago by viboes

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

Committed revision 82491.

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.