I have a huge code (its my school project) where I use Openssl. Everything was working perfeclty, util I decided I will go multithreaded. I chose openmp as my threading environment, since its very simple and pretty easy to learn (at least the basis I need are easy).
My whole code looks like this:
struct mystr[10];
omp_set_num_threads(10);
#pragma omp parallel
{
mystr[omp_get_thread_num()] = call_fun_which_uses_openssl();
}
CRYPTO_cleanup_all_ex_data();
My call_fun_which_uses_openssl function uses low level openssls api functions (MD4((unsigned char*)&string, strlen(string), (unsigned char*)&digest); instead of MD4_CTX ctx etc). My function uses RSA, DSA, ... and does not have access to any global variables, every variable it uses is declared inside call_fun_which_uses_openssl, so doing a multithreading like I did should guarantee that those variables remain private. Although, I sometimes have seg faults with this code. I read that CRYPTO_cleanup_all_ex_data is not thread-safe (but I need it because of memory leaks) but I use it outside the parallel region, right? When I remove openmp calls everything works every time so there must be an issue with multithreading and openssl. Any ideas how to solve it?
In my opinion it should work, beacuse a threaded call of call_fun_which_uses_openssl creates its own private variables for every thread and there should be no problem ... Please, help :)