lock-free

Is it possible to implement lock free map in C++

喜夏-厌秋 提交于 2019-11-27 19:48:37
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. I wonder if it is possible to implement a lock-free map, if yes, how? Is there any open source code there? EDIT: 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, then every thread which is used

Do spin locks always require a memory barrier? Is spinning on a memory barrier expensive?

大兔子大兔子 提交于 2019-11-27 15:16:19
问题 I wrote some lock-free code that works fine with local reads, under most conditions. Does local spinning on a memory read necessarily imply I have to ALWAYS insert a memory barrier before the spinning read? (To validate this, I managed to produce a reader/writer combination which results in a reader never seeing the written value, under certain very specific conditions--dedicated CPU, process attached to CPU, optimizer turned all the way up, no other work done in the loop--so the arrows do

How do I specify the equivalent of volatile in VB.net?

时光总嘲笑我的痴心妄想 提交于 2019-11-27 15:12:30
I'm attempting to write a lock-free version of a call queue I use for message passing. This is not for anything serious, just to learn about threading. I'm relatively sure my code is correct, except if the instructions are re-ordered or done in registers. I know I can use memory barriers to stop re-ordering, but how can I ensure values are written to memory immediately? Public Class CallQueue Private first As New Node(Nothing) 'owned by consumer' Private last As Node = first 'owned by producers' Private Class Node Public ReadOnly action As Action Public [next] As Node Public Sub New(ByVal

Is a lock (wait) free doubly linked list possible?

落爺英雄遲暮 提交于 2019-11-27 12:32:35
问题 Asking this question with C# tag, but if it is possible, it should be possible in any language. Is it possible to implement a doubly linked list using Interlocked operations to provide no-wait locking? I would want to insert, add and remove, and clear without waiting. 回答1: A simple google search will reveal many lock-free doubly linked list papers. However, they are based on atomic CAS (compare and swap). I don't know how atomic the operations in C# are, but according to this website http:/

Lock free stack and queue in C#

自古美人都是妖i 提交于 2019-11-27 12:00:15
问题 Does anyone know if there are any lock-free container libraries available for .NET ? Preferably something that is proven to work and faster than the Synchronized wrappers we have in .NET. I have found some articles on the .NET, but none of them specify any speed benchmarking, nor do they inspire much confidence in their reliability. Thanks 回答1: Late, but better than never I thought I would add Julian Bucknalls articles to this list. But he does not have performance numbers. In my testing of

Lock Free Queue — Single Producer, Multiple Consumers

旧城冷巷雨未停 提交于 2019-11-27 11:18:26
问题 I am looking for a method to implement lock-free queue data structure that supports single producer, and multiple consumers. I have looked at the classic method by Maged Michael and Michael Scott (1996) but their version uses linked lists. I would like an implementation that makes use of bounded circular buffer. Something that uses atomic variables? On a side note, I am not sure why these classic methods are designed for linked lists that require a lot of dynamic memory management. In a multi

Portable Compare And Swap (atomic operations) C/C++ library?

帅比萌擦擦* 提交于 2019-11-27 10:52:59
Is there any small library, that wrapps various processors' CAS-like operations into macros or functions, that are portable across multiple compilers? PS. The atomic.hpp library is inside boost::interprocess::detail namespace. The author refuses to make it a public, well maintained library. Lets reopen the question, and see if there are any other options? Intel Threading Building Blocks has a nice portable atomic<T> template which does what you want. But whether it is a small library or not can of course be debated.. OPA (Open Portable Atomics) could be a good fit for your needs. https://trac

atomic operation cost

谁说我不能喝 提交于 2019-11-27 10:21:09
What is the cost of the atomic operation (any of compare-and-swap or atomic add/decrement)? How much cycles does it consume? Will it pause other processors on SMP or NUMA, or will it block memory accesses? Will it flush reorder buffer in out-of-order CPU? What effects will be on the cache? I'm interested in modern, popular CPUs: x86, x86_64, PowerPC, SPARC, Itanium. Blaisorblade I have looked for actual data for the past days, and found nothing. However, I did some research, which compares the cost of atomic ops with the costs of cache misses. The cost of the x86 LOCK prefix, or CAS, before

Lock-free multi-threading is for real threading experts

纵然是瞬间 提交于 2019-11-27 08:56:04
问题 I was reading through an answer that Jon Skeet gave to a question and in it he mentioned this: As far as I'm concerned, lock-free multi-threading is for real threading experts, of which I'm not one. Its not the first time that I have heard this, but I find very few people talking about how you actually do it if you are interested in learning how to write lock-free multi-threading code. So my question is besides learning all you can about threading, etc where do you start trying to learn to

Do lock-free algorithms really perform better than their lock-full counterparts?

邮差的信 提交于 2019-11-27 05:08:07
问题 Raymond Chen has been doing a huge series on lockfree algorithms. Beyond the simple cases of the InterlockedXxx functions, it seems like the prevailing pattern with all of these is that they implement their own locks . Sure, there are not processor locks, but the concept of looping over and over on each CPU to ensure consistency is very much like a spinlock. And being a spinlock, they are going to be less efficient than the general locks that come with the operating system because they do not