多线程和全局互斥的并发访问(Concurrent access by multiple threads and global mutex)

编程入门 行业动态 更新时间:2024-10-27 07:25:38
多线程和全局互斥的并发访问(Concurrent access by multiple threads and global mutex)

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.

更多推荐

本文发布于:2023-07-26 03:45:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1270680.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:全局   多线程   互斥   Concurrent   access

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!