This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/52604] mt allocator crashes on multi-threaded
- From: "laurent.alfonsi at st dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 16 Mar 2012 15:25:23 +0000
- Subject: [Bug libstdc++/52604] mt allocator crashes on multi-threaded
- Auto-submitted: auto-generated
- References: <bug-52604-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52604
--- Comment #1 from Laurent Aflonsi <laurent.alfonsi at st dot com> 2012-03-16 15:25:23 UTC ---
I would propose to fix as follows :
- Set the _M_Key=NULL when calling the freelist desctuctor.
- Testing the NULL Key before using it with setspecific.
see patch below :
===================================================================
--- libstdc++-v3/src/mt_allocator.cc (revision 2486)
+++ libstdc++-v3/src/mt_allocator.cc (working copy)
@@ -47,6 +47,7 @@
if (_M_thread_freelist_array)
{
__gthread_key_delete(_M_key);
+ _M_key = NULL;
::operator delete(static_cast<void*>(_M_thread_freelist_array));
}
}
@@ -639,7 +640,8 @@
}
}
- __gthread_setspecific(freelist._M_key, (void*)_M_id);
+ if (freelist._M_key)
+ __gthread_setspecific(freelist._M_key, (void*)_M_id);
}
return _M_id >= _M_options._M_max_threads ? 0 : _M_id;
}
===================================================================
Let me know what you think
Thanks very much
Laurent Alfonsi