通过多个线程和全局互斥锁并发访问 [英] Concurrent access by multiple threads and global mutex

查看:74
本文介绍了通过多个线程和全局互斥锁并发访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OpenSSL常见问题解答指出它可以在线程应用程序中使用:

The OpenSSL FAQ states that it can be used in threaded applications:

1. OpenSSL线程安全吗?

提供了一个设置线程回调函数的应用程序,答案是肯定的.

Provided an application sets up the thread callback functions, the answer is yes.

此回调函数引用了全局SSL锁,因此,如果您有2个运行的ssl连接,则它们都将使用此全局锁.

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:

有局限性;例如,多个线程不能同时使用SSL连接.对于大多数OpenSSL对象来说都是如此.

There are limitations; for example, an SSL connection cannot be used concurrently by multiple threads. This is true for most OpenSSL objects.

这表示每个SSL连接都需要一个附加的互斥量.这样对吗?还是我不需要为每个SSL连接使用其他互斥锁?

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.

这篇关于通过多个线程和全局互斥锁并发访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆