Ask Your Question
1

pthread_key_create fails after loading library with Boost unit test

asked 2019-11-22 02:15:22 -0500

flaterik gravatar image

updated 2019-11-27 10:32:36 -0500

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 == 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?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2019-11-27 10:32:21 -0500

flaterik gravatar image

We found out that the local storage was allocated by the Logging/TraceManager each time the library is loaded. So, one solution to circumvent the problem is to deactivate the build flag CV_TRACE. This way, no local storage is created during library loading and we don't run into the pthread key overflow.

That doesn't explain the error but is sufficient to finally get rid of it.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-11-22 02:15:22 -0500

Seen: 32 times

Last updated: Nov 27 '19