OpenSSL FAQ声明它可以在线程应用程序中使用:
1. OpenSSL是否是线程安全的?
如果应用程序设置了线程回调函数,答案是肯定的。
此回调函数引用全局SSL锁定,因此如果您有2个ssl连接运行,则这两个连接都将使用此全局锁定。
然而常见问题继续:
有局限性; 例如,多个线程不能同时使用SSL连接。 大多数OpenSSL对象都是如此。
这表示每个SSL连接都需要一个额外的互斥锁。 它是否正确? 或者我不需要为每个SSL连接添加额外的互斥锁?
The OpenSSL FAQ states that it can be used in threaded applications:
1. Is OpenSSL thread-safe?
Provided an application sets up the thread callback functions, the answer is yes.
This callback functions refers to a global SSL-lock, thus if you have 2 ssl connections running these will both use this global lock.
However the FAQ continues:
There are limitations; for example, an SSL connection cannot be used concurrently by multiple threads. This is true for most OpenSSL objects.
This indicates that an additional mutex is needed for every SSL-connection. Is this correct? Or do I not need the additional mutex for every SSL-connection?
最满意答案
这意味着如果您的连接由多个线程共享 ,则需要使用互斥锁以避免它们同时操作连接。
只要任何单个连接一次仅由一个线程使用(在大多数应用程序中是正常情况),您就不需要任何进一步的锁定。
It means that if your connection is shared by multiple threads, you need to have a mutex to avoid them all manipulating the connection at the same time.
As long as any single connection is only used by one thread at a time (which in most applications is the normal case), you don't need any further locking.
更多推荐
发布评论