Access to opencv thread pool

asked 2020-01-09 01:35:05 -0500

Hello, I have a dynamic library which is statically linked with OpenCV. That library is opened via dlopen by a linux application and does some image processing. OpenCV uses pthreads for parallelisation. And here is a problem. After finishing image processing and closing library via dlclose application crashes with segmentation fault. After debugging I found out that at the moment of calling dlclose there were still some active threads, created by opencv, though all image processing routines had already finished. I've tried using global destructor function marked with __attribute__((destructor)) and call cv::setNumThreads(1); but sometimes application still crashes. The one solution that helped me was setting a small time delay in the destructor, so opencv threads manage to close somehow. Is there any solution to force explicitly closing all threads or may be poll a status of opencv thread pool to wait when it's safe to unload dynamic library?

edit retag flag offensive close merge delete


If you can write a small example then it will be easyer to reproduce issue

LBerger gravatar imageLBerger ( 2020-01-09 02:40:18 -0500 )edit