On vxworks, after destroying the semaphore used to implement a mutex,
__gthread_mutex_lock fails and __gnu_cxx::__mutex::lock calls
__throw_concurrence_lock_error. Nothing ensures the mutex_pool
mutexes survive init-once objects containing _Safe_sequence_base. If
such an object completes construction before mutex_pool
initialization, it will be registered for atexit destruction after the
mutex_pool mutexes, so the _M_detach_all() call in the
_Safe_sequence_base dtor will use already-destructed mutexes, and
basic_string/requirements/citerators_cc fails calling terminate.
This patch fixes this problem by ensuring the mutex pool mutexes are
constructed on demand, on a statically-allocated buffer, but never
destructed.
for libstdc++-v3/ChangeLog
* src/c++11/shared_ptr.cc (__gnu_internal::get_mutex):
Avoid destruction of the mutex pool.
{
// increase alignment to put each lock on a separate cache line
struct alignas(64) M : __gnu_cxx::__mutex { };
- static M m[mask + 1];
+ // Use a static buffer, so that the mutexes are not destructed
+ // before potential users (or at all)
+ static __attribute__ ((aligned(__alignof__(M))))
+ char buffer[(sizeof (M)) * (mask + 1)];
+ static M *m = new (buffer) M[mask + 1];
return m[i];
}
}