Frederick wrote: > > CRYPTO_THREAD_write_lock(rand_meth_lock); > CRYPTO_THREAD_write_lock(rand_engine_lock); This is what's causing the segfault in libpthread.so I can only imagine that the same thread is trying to re-lock a single-lock mutex. So my code should be something like: int already_locked_meth = is_already_locked(rand_meth_lock); int already_locked_engine = is_already_locked(rand_engine_lock); if (!already_locked_meth) CRYPTO_THREAD_write_lock(rand_meth_lock); if (!already_locked_engine) CRYPTO_THREAD_write_lock(rand_engine_lock); /* DO STUFF */ if (!already_locked_meth) CRYPTO_THREAD_unlock(rand_meth_lock); if (!already_locked_engine) CRYPTO_THREAD_unlock(rand_engine_lock);