多线程环境下使用openssl

使用旧版本openssl时,需要设置两个回调

The documentation on OpenSSL threads states (at least for version 1.0.2):
OpenSSL can safely be used in multi-threaded applications provided that at least two
callback functions are set, locking_function and threadid_func.

但是在1.1.0以及更新的版本中,不再需要这个设置了

The ChangeLog of version 1.1.0 states:
OpenSSL now uses a new threading API. It is no longer necessary to
set locking callbacks to use OpenSSL in a multi-threaded environment. There
are two supported threading models: pthreads and windows threads. It is
also possible to configure OpenSSL at compile time for "no-threads". The
old threading API should no longer be used. The functions have been
replaced with "no-op" compatibility macros.
[Alessandro Ghedini, Matt Caswell]

#  if OPENSSL_API_COMPAT < 0x10000000L
#   define CRYPTO_set_id_callback(func)
#   define CRYPTO_get_id_callback()                     (NULL)
#   define CRYPTO_thread_id()                           (0UL)
#  endif /* OPENSSL_API_COMPAT < 0x10000000L */
/*
 * The old locking functions have been removed completely without compatibility
 * macros. This is because the old functions either could not properly report
 * errors, or the returned error values were not clearly documented.
 * Replacing the locking functions with no-ops would cause race condition
 * issues in the affected applications. It is far better for them to fail at
 * compile time.
 * On the other hand, the locking callbacks are no longer used.  Consequently,
 * the callback management functions can be safely replaced with no-op macros.
 */
#  define CRYPTO_num_locks()            (1)
#  define CRYPTO_set_locking_callback(func)
#  define CRYPTO_get_locking_callback()         (NULL)
#  define CRYPTO_set_add_lock_callback(func)
#  define CRYPTO_get_add_lock_callback()        (NULL)
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,490评论 0 10
  • 燕子去了,有再来的时候;杨柳枯了,有再青的时候;桃花谢了,有再开的时候。有些东西失去了就在也回不来了一生命,生命是...
    单伊梵0321阅读 566评论 0 4
  • 在那西部, 我邂逅一片沙漠。 在我眼里, 她是迟暮的美人。 探赜索隐, 她那多变的表情。 她笑了, 悄无声而骆驼知...
    遇上音阶阅读 396评论 2 0