[Bug libstdc++/94936] pmr::synchronized_pool_resource crashes without -pthread
cvs-commit at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon May 4 13:35:52 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94936
--- Comment #1 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:
https://gcc.gnu.org/g:ec40967f1323069da3a5a45286f71fa4f80926df
commit r11-40-gec40967f1323069da3a5a45286f71fa4f80926df
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Mon May 4 13:34:23 2020 +0100
libstdc++: Make pmr::synchronized_pool_resource work without libpthread (PR
94936)
I implicitly assumed that programs using pmr::synchronized_pool_resource
would also be using multiple threads, and so the weak symbols in
gthr-posix.h would be resolved by linking to libpthread. If that isn't
true then it crashes when trying to use pthread_key_create.
This commit makes the pool resource check __gthread_active_p() before
using thread-specific data, and just use a single set of memory pools
when there's only a single thread.
PR libstdc++/94936
* src/c++17/memory_resource.cc
(synchronized_pool_resource::_TPools):
Add comment about single-threaded behaviour.
(synchronized_pool_resource::_TPools::move_nonempty_chunks()):
Hoist
class member access out of loop.
(synchronized_pool_resource::synchronized_pool_resource())
(synchronized_pool_resource::~synchronized_pool_resource())
(synchronized_pool_resource::release()): Check __gthread_active_p
before creating and/or deleting the thread-specific data key.
(synchronized_pool_resource::_M_thread_specific_pools()): Adjust
assertions.
(synchronized_pool_resource::do_allocate(size_t, size_t)): Add fast
path for single-threaded case.
(synchronized_pool_resource::do_deallocate(void*, size_t, size_t)):
Likewise. Return if unable to find a pool that owns the allocation.
* testsuite/20_util/synchronized_pool_resource/allocate_single.cc:
New test.
* testsuite/20_util/synchronized_pool_resource/cons_single.cc: New
test.
* testsuite/20_util/synchronized_pool_resource/release_single.cc:
New
test.
More information about the Gcc-bugs
mailing list