Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pthread key leak #363

Open
Mario-Klebsch opened this issue Dec 2, 2021 · 0 comments
Open

pthread key leak #363

Mario-Klebsch opened this issue Dec 2, 2021 · 0 comments

Comments

@Mario-Klebsch
Copy link

Mario-Klebsch commented Dec 2, 2021

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(&current_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 47357de 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant