pthread key leak
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- cpp, linux
- Domain
- operating-systems
Research direction
Start with libs/thread/src/pthread/thread.cpp, especially create_current_thread_tls_key(), and reproduce the repeated shared-library load/unload case from boost_pthread_key_leak.zip. Read commit 47357de276fe4fc01469f34c1dbf8b26fdbc1c4b and ticket #12049 to understand the existing race-related behavior. Done means resolving the pthread key leak without reintroducing the reported issue.
Written by the indexing model from the issue text.
Description
I am using boost::thread statically linkes in a shared library and found a pthread key leak. When I repeat loading and unloading the library, pthread keys are leaking and after some time, I get
main: boost_1_77_0/libs/thread/src/pthread/thread.cpp:148: void boost::detail::{anonymous}::create_current_thread_tls_key(): Assertion `!pthread_key_create(¤t_thread_tls_key,&tls_destructor)' failed.
The leaking pthread key is allocated in libs/thread/src/pthread/thread.cpp. The code for de-allocating the pthread key is #ifdef'ed with BOOST_THREAD_PATCH. Without BOOST_THREAD_PATCH, the binary only calls to pthread_key_create, but no call to pthread_key_delete:
The problem seems to be solved, if I #define BOOST_THREAD_PATCH. But this #ifdef was added in 47357de276fe4fc01469f34c1dbf8b26fdbc1c4b to solve bug #12049. (https://www.boost.org/doc/libs/1_64_0/doc/html/thread/changes.html) (https://svn.boost.org/trac10/ticket/12049)
Unfortunately, I do not really understand the problem in ticket #12049. To me, it looks like a race condition and the leaking pthread key just prevents any harm caused by the race condition. That doesn't really look like a fix to me, just solves one problem by creating a new one. :-(
Here is my source code: boost_pthread_key_leak.zip
I am using linux on x86_64, c++ (Gentoo 10.3.0-r2 p3) 10.3.0
- Dominant language
- C++
- Stars
- 213
- Forks
- 171
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from boostorg/thread
-
Difficulty 1/5 Under an hour Newbie friendliness 65/100
-
Difficulty 3/5 1-2 days Newbie friendliness 64/100
-
Difficulty 3/5 1-2 days Newbie friendliness 42/100
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 58/100
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
AXERA-TECH/ax-llm#77 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
games-on-whales/wolf#509 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
bug-unconfirmed
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
NVIDIA/cuda-samples#453 ·