title: Openssl synchronization in native JNI C code
body: <p>I am currently writing a JNI wrapper for a shared C library, which implements some cryptographic functions using the openssl library. The JNI wrapper will be used in a multi-threaded Java application, meaning that the C functions will be called concurrently from multiple Java threads.</p>
  
  <p>Unfortunately the opensssl library is "out of the box" not thread-safe, but the user has to implement and register certain synchronization callback functions which the openssl library will use for synchronization. For more details see <a href="https://www.openssl.org/support/faq.html#PROG1" rel="nofollow">here</a>.</p>
  
  <p>Now in order to implement those callback functions, I would use for example the <code>pthread</code> mutexes on platforms where the POSIX threads are available, but I am not so sure, if it is safe to do so since we are dealing here with the <strong>Java threads</strong> created by the JVM.</p>
  
  <p>How should I proceed? Are there any good examples or documentations which I can learn from?
  Thanks in advance for your help!</p>