Opened 14 years ago

Closed 13 years ago

#2681 closed Bugs (fixed)

lwm_pthread fails to catch initialization error

Reported by: Olivier Langlois <olivier.langlois@…> Owned by: Peter Dimov
Milestone: Boost 1.38.0 Component: smart_ptr
Version: Boost 1.37.0 Severity: Problem
Keywords: Cc: olivier.langlois@…, jwakely.boost@…

Description

pthread_mutex_init() return value is not checked and if the mutex creation fails, the next pthread_mutex_lock() call result is undefined on some platforms.

I think that it would be appropriate to throw an exception from the lightweight_mutex constructor if pthread_mutex_init fails.

The problem is in

boost/detail/lwm_pthreads.hpp

Change History (5)

comment:1 by Olivier Langlois <olivier.langlois@…>, 14 years ago

Cc: olivier.langlois@… added

I can give more details on how I stumbled on the problem. I had this bad statement in my code which had the intent of reseting boost::shared_ptr

reset shared pointer my_ptr = boost::shared_ptr<MyClass>(static_cast<MyClass *>(NULL));

So for each 'reset', a new ref counter with its mutex was created. After few thousands of 'reset', pthread_mutex_init() eventually returned ENOMEM which was not catched by boost as described in the initial description.

and finally on the next pthread_mutex_lock with the unitialized mutex, on my OS (CentOS 4), the program just block inside the call and never return.

comment:2 by Jonathan Wakely <jwakely.boost@…>, 13 years ago

Cc: jwakely.boost@… added
Component: threadssmart_ptr
Owner: changed from Anthony Williams to Peter Dimov

I think lwm_pthreads.hpp belongs to the smart_ptr component not threads.

Boost.Threads asserts that the pthread calls succeed, e.g.

        BOOST_VERIFY( !pthread_mutex_init(&m_, 0) );

but I don't know if lightweight_mutex wants to avoid that overhead.

comment:3 by Peter Dimov, 13 years ago

(In [57953]) Add error checking to lwm_pthreads.hpp. Refs #2681.

comment:4 by Peter Dimov, 13 years ago

Status: newassigned

comment:5 by Peter Dimov, 13 years ago

Resolution: fixed
Status: assignedclosed

(In [58065]) Merge [57953] to release. Fixes #2681.

Note: See TracTickets for help on using tickets.