-
Notifications
You must be signed in to change notification settings - Fork 258
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
thread specific key leakage #789
Comments
It's a little bit trickier than this because Why are you looping |
It makes sense. We are library provider, it's our user who make such stress testing. So we can suggest them to skip this test case. However, the stress testing do make sense when the final product is a plugin/shared library. |
libc++ also intentionally leaks the pthread_keys used for notify_all_at_thread_exit() and __cxa_thread_atexit(). dlclose() on libc++(abi) is not really supported. Maybe you could load it with RTLD_NODELETE? |
…t create thread specific key for __cxa_get_globals()' (see android/ndk#789)
Forgot to close this one. Like @tavianator said, these are intentionally leaked by libc++abi as a necessity of the fallback Devices running 23+ will get the non-fallback behavior. If you need to avoid the leak for earlier platforms, there are a few workarounds:
|
Thanks for detailed explanation. I have a follow up question.
If 1. and 2. are not an option, does 3. mean not using std::thread at all? |
No, you can use But if 1 isn't an option you should probably re-evaluate your implementation. |
https://developer.android.com/ndk/guides/cpp-support recommends using c++_shared for applications that use more than one shared library. If multiple libraries using c++_static are loaded you end up with several copies of the globals in the C++ runtime. This also happens if the same library is dlopen/dlclosed several times. Some of the c++ runtime globals are thread_local, so each copy consumes a TLS key. There are only 128 TLS keys allowed on android, and the unit tests can hit this because of repeatedly loading and unloading VVL. See android/ndk#789 and the many issues linked to it for more info.
https://developer.android.com/ndk/guides/cpp-support recommends using c++_shared for applications that use more than one shared library. If multiple libraries using c++_static are loaded you end up with several copies of the globals in the C++ runtime. This also happens if the same library is dlopen/dlclosed several times. Some of the c++ runtime globals are thread_local, so each copy consumes a TLS key. There are only 128 TLS keys allowed on android, and the unit tests can hit this because of repeatedly loading and unloading VVL. See android/ndk#789 and the many issues linked to it for more info.
https://developer.android.com/ndk/guides/cpp-support recommends using c++_shared for applications that use more than one shared library. If multiple libraries using c++_static are loaded you end up with several copies of the globals in the C++ runtime. This also happens if the same library is dlopen/dlclosed several times. Some of the c++ runtime globals are thread_local, so each copy consumes a TLS key. There are only 128 TLS keys allowed on android, and the unit tests can hit this because of repeatedly loading and unloading VVL. See android/ndk#789 and the many issues linked to it for more info.
https://developer.android.com/ndk/guides/cpp-support recommends using c++_shared for applications that use more than one shared library. If multiple libraries using c++_static are loaded you end up with several copies of the globals in the C++ runtime. This also happens if the same library is dlopen/dlclosed several times. Some of the c++ runtime globals are thread_local, so each copy consumes a TLS key. There are only 128 TLS keys allowed on android, and the unit tests can hit this because of repeatedly loading and unloading VVL. See android/ndk#789 and the many issues linked to it for more info.
https://developer.android.com/ndk/guides/cpp-support recommends using c++_shared for applications that use more than one shared library. If multiple libraries using c++_static are loaded you end up with several copies of the globals in the C++ runtime. This also happens if the same library is dlopen/dlclosed several times. Some of the c++ runtime globals are thread_local, so each copy consumes a TLS key. There are only 128 TLS keys allowed on android, and the unit tests can hit this because of repeatedly loading and unloading VVL. See android/ndk#789 and the many issues linked to it for more info.
Description
We build a program which use
ostream
and when we do stress testing by repeated loading and unloading the built shared library, the program crashed with an abort messagecannot create thread specific key for __cxa_get_globals()
here:which means
pthread_key_create
returns error.And checked the source of bionic implementation for
pthread_key_create
https://github.com/aosp-mirror/platform_bionic/blob/master/libc/bionic/pthread_key.cpp#L120:Which means it will fail when there is no free slot (with 130 as the max).
And from the code above, there is no matching
pthread_key_delete
indestruct_
call. This will create a leak for each loading.Environment Details
The program is based on 17b which is not the latest, however, the source code section should be enough.
The text was updated successfully, but these errors were encountered: