Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

pthread_key_create fails after loading library with Boost unit test

Hey guys,

I'm using OpenCV 4.1.1 in my companies C++ project. We built a dynamic library that is linked against OpenCV. Everything works fine unless we test our library inside a Boost unit test under Linux. In there we load our library and unload it repeatedly and after the 1024th time the following OpenCV error pops up:

  error: (-215:Assertion failed) pthread_key_create(&tlsKey, NULL) == 0 in function 'TlsAbstraction

So far my understanding is that under Linux we can create at most 1024 pthread keys (PTHREAD_KEYS_MAX == 2014) per process for local storage. Meaning that the local storage created by OpenCV is not freed once our library is unloaded. If we do the same outside of a Boost unit test everything is fine. Of course, it's possible that the problem is only based on Boost. However, this behavior started when we updated OpenCV from version 3.1.0 to 4.1.1.

Linux: Oracle Linux Server release 7.7 (64 bit)

Boost: 1.64.0

OpenCV: 4.1.1

Do you have any ideas why it happens and how it could be prevented?

pthread_key_create fails after loading library with Boost unit test

Hey guys,

I'm using OpenCV 4.1.1 in my companies C++ project. We built a dynamic library that is linked against OpenCV. Everything works fine unless we test our library inside a Boost unit test under Linux. In there we load our library and unload it repeatedly and after the 1024th time the following OpenCV error pops up:

  error: (-215:Assertion failed) pthread_key_create(&tlsKey, NULL) == 0 in function 'TlsAbstraction

So far my understanding is that under Linux we can create at most 1024 pthread keys (PTHREAD_KEYS_MAX == 2014) 1024) per process for local storage. Meaning that the local storage created by OpenCV is not freed once our library is unloaded. If we do the same outside of a Boost unit test everything is fine. Of course, it's possible that the problem is only based on Boost. However, this behavior started when we updated OpenCV from version 3.1.0 to 4.1.1.

Linux: Oracle Linux Server release 7.7 (64 bit)

Boost: 1.64.0

OpenCV: 4.1.1

Do you have any ideas why it happens and how it could be prevented?