try adding some thread initialization logic

this includes a real version and a cheater version.  it may be necessary to use
the cheater version as the _ssl module in the stdlib is just going to trample
whatever we try to do anyway.
diff --git a/OpenSSL/crypto.py b/OpenSSL/crypto.py
index 3178b5a..0c78b31 100644
--- a/OpenSSL/crypto.py
+++ b/OpenSSL/crypto.py
@@ -2227,3 +2227,33 @@
     pkcs12._cacerts = pycacerts
     pkcs12._friendlyname = friendlyname
     return pkcs12
+
+
+def _initialize_openssl_threads(get_ident, Lock):
+    import _ssl
+    return
+
+    locks = list(Lock() for n in range(_lib.CRYPTO_num_locks()))
+
+    def locking_function(mode, index, filename, line):
+        if mode & _lib.CRYPTO_LOCK:
+            locks[index].acquire()
+        else:
+            locks[index].release()
+
+    _lib.CRYPTO_set_id_callback(
+        _ffi.callback("unsigned long (*)(void)", get_ident))
+
+    _lib.CRYPTO_set_locking_callback(
+        _ffi.callback(
+            "void (*)(int, int, const char*, int)", locking_function))
+
+
+try:
+    from thread import get_ident
+    from threading import Lock
+except ImportError:
+    pass
+else:
+    _initialize_openssl_threads(get_ident, Lock)
+    del get_ident, Lock