它是possbile实行锁免费地图在C ++它是、地图、possbile

2023-09-10 23:54:59 作者:夏初花未谢°

我们正在开发一个基于网络的应用程序的C / S,我们发现有太多的锁加入到std ::地图的服务器的性能变差。

We are developing a network application based C/S, we find there are too many locks adding to std::map that the performance of server became poor.

我不知道是否有可能实现一个无锁的地图,如果是的话,怎么办?是否有任何开源$ C ​​$ C呢?

I wonder if it is possible to implement a lock-free map, if yes, how? Is there any open source code there?

编辑: 其实我们使用std ::地图存储插槽的信息,我们也基于socket文件描述的封装,包括一些其他必要信息,如IP地址,端口,插槽类型,TCP或UDP等。

Actually we use the std::map to store sockets information, we did encapsulation based on the socket file description to include some other necessary information such as ip address, port, socket type, tcp or udp, etc.

要总结,我们有一个全球性的地图说这是

To summary, we have a global map say it's

map<int fileDescriptor, socketInfor*> SocketsMap, 

然后它被用来发送数据的每个线程需要访问SocketsMap,并且他们必须读取SocketsMap或写入SocketsMap之前添加互斥,从而整个应用程序的并发水平将大大下降,因为如此多的锁定addding以SocketsMap。

then every thread which is used to send data needs to access SocketsMap, and they have to add mutex before reading from SocketsMap or writing to SocketsMap, thus the concurrency level of the whole application would be greatly decreased because of so many locks addding to SocketsMap.

要避免并发级别的问题,我们有两个解决方案:1。每个专卖店* socketInfor 2.单独使用某种形式的无锁的地图。

To avoid the concurrency level problem, we have two solutions: 1. store each socketInfor* separately 2. use some kind of lock-free map.

我想找到某种无锁的地图,因为codeS这个解决方案需要的变化比的解决方案1.要少得多

I would like to find some kind of lock-free map, because codes changes required by this solution are much less than that of solution 1.

推荐答案

其实有一个办法,虽然我还没有实现它自己有一份文件上的使用危险的指针由著名ç的锁定免费地图+专家安德烈·Alexandrescu的。

Actually there's a way, although I haven't implemented it myself there's a paper on a lock free map using hazard pointers from eminent C++ expert Andrei Alexandrescu.