Opened 14 years ago
Closed 13 years ago
#2681 closed Bugs (fixed)
lwm_pthread fails to catch initialization error
Reported by: | 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 , 14 years ago
Cc: | added |
---|
comment:2 by , 13 years ago
Cc: | added |
---|---|
Component: | threads → smart_ptr |
Owner: | changed from | to
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:4 by , 13 years ago
Status: | new → assigned |
---|
comment:5 by , 13 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
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.