The problem scenario is the following:
A dynamic library, libfoo.so, depends on libomp.so (it creates parallel region and calls some omp functions).
An application has a loop where it dynamically loads libfoo.so, calls the function from it, unloads libfoo.so.
After several loop iterations application crashes with the message about lack of resources
OMP: Error #34: System unable to allocate necessary resources for OMP thread:
The problem is that pthread_kill() was not followed by pthread_join() in case of terminated thread. This patch fixes this problem for both worker and monitor threads.