Message ID | 4F90107D.6010200@st.com |
---|---|
State | New |
Headers | show |
Hi, > All, > > The enclosed testcases (very close to > ext/mt_allocator/deallocate_global_thread-1.cc) exposes a pattern > where the following sequence is called (when __gthread_active_p is > enabled) : > > __gthread_key_create(&key,::_M_destroy_thread_key); > __gthread_setspecific(key, (void*)_M_id); > __gthread_key_delete(key); > __gthread_setspecific(key, (void*)_M_id); I didn't look into the issue in any detail - and I'm really glad that you are interested in improving mt_allocator - but I think that before going for quick patches, we should strive for fixing the underlying issue, eg prevent the above from occurring. After all, if you are right, the issue is very, very old, and nobody complained yet, thus better try very hard to fix it for real, finally. Do you have any plans for that? Thanks, Paolo.
Well, I don't know mt_allocator enough to know if this is a fix for real or a quick fix. Regards, Laurent On 04/19/12 16:26, Paolo Carlini wrote: > Hi, >> All, >> >> The enclosed testcases (very close to >> ext/mt_allocator/deallocate_global_thread-1.cc) exposes a pattern >> where the following sequence is called (when __gthread_active_p is >> enabled) : >> >> __gthread_key_create(&key,::_M_destroy_thread_key); >> __gthread_setspecific(key, (void*)_M_id); >> __gthread_key_delete(key); >> __gthread_setspecific(key, (void*)_M_id); > I didn't look into the issue in any detail - and I'm really glad that > you are interested in improving mt_allocator - but I think that before > going for quick patches, we should strive for fixing the underlying > issue, eg prevent the above from occurring. After all, if you are right, > the issue is very, very old, and nobody complained yet, thus better try > very hard to fix it for real, finally. Do you have any plans for that? > > Thanks, > Paolo. >
On 04/19/2012 05:02 PM, Laurent Alfonsi wrote: > Well, I don't know mt_allocator enough to know if this is a fix for > real or a quick fix. I'm pretty sure we could do better. Whether in practice we are going to do better, any time soon, it's another matter ;) Paolo.
Thanks very much Paolo. I'll apply this patch on my side for a while. I ll tell you if i see anything strange. Regards, Laurent On 04/19/12 17:52, Paolo Carlini wrote: > On 04/19/2012 05:02 PM, Laurent Alfonsi wrote: >> Well, I don't know mt_allocator enough to know if this is a fix for >> real or a quick fix. > I'm pretty sure we could do better. Whether in practice we are going to > do better, any time soon, it's another matter ;) > > Paolo. >
Index: src/c++98/mt_allocator.cc =================================================================== --- src/c++98/mt_allocator.cc.orig +++ src/c++98/mt_allocator.cc @@ -34,19 +34,22 @@ namespace { #ifdef __GTHREADS + const __gthread_key_t ILLEGAL_THREAD_KEY = -1; + struct __freelist { typedef __gnu_cxx::__pool<true>::_Thread_record _Thread_record; _Thread_record* _M_thread_freelist; _Thread_record* _M_thread_freelist_array; size_t _M_max_threads; - __gthread_key_t _M_key; + __gthread_key_t _M_key = ILLEGAL_THREAD_KEY; ~__freelist() { if (_M_thread_freelist_array) { __gthread_key_delete(_M_key); + _M_key = ILLEGAL_THREAD_KEY; ::operator delete(static_cast<void*>(_M_thread_freelist_array)); _M_thread_freelist = 0; } @@ -640,7 +643,8 @@ } } - __gthread_setspecific(freelist._M_key, (void*)_M_id); + if (freelist._M_key!=ILLEGAL_THREAD_KEY) + __gthread_setspecific(freelist._M_key, (void*)_M_id); } return _M_id >= _M_options._M_max_threads ? 0 : _M_id; }