lock-free

Memory barriers in userspace? (Linux, x86-64)

可紊 提交于 2019-12-03 02:27:10
问题 It is easy to set memory barriers on the kernel side: the macros mb, wmb, rmb, etc. are always in place thanks to the Linux kernel headers. How to accomplish this on the user side? 回答1: Posix defines a number of functions as acting as memory barriers. Memory locations must not be concurrently accessed; to prevent this, use synchronization - and that synchronization will also work as a barrier. 回答2: You are looking for the full memory barrier atomic builtins of gcc. Please note the detail on

Using Boost.Lockfree queue is slower than using mutexes

。_饼干妹妹 提交于 2019-12-03 01:02:30
问题 Until now I was using std::queue in my project. I measured the average time which a specific operation on this queue requires. The times were measured on 2 machines: My local Ubuntu VM and a remote server. Using std::queue , the average was almost the same on both machines: ~750 microseconds. Then I "upgraded" the std::queue to boost::lockfree::spsc_queue , so I could get rid of the mutexes protecting the queue. On my local VM I could see a huge performance gain, the average is now on 200

Lock free & Thread-Safe IList<T> for .NET

断了今生、忘了曾经 提交于 2019-12-02 20:51:20
Is there a lock-free & thread-safe data structure that implements IList? Naturally by lock-free I mean an implementation that makes no use of locking primitives in .NET but rather uses interlocked operations / atomic operations to achieve thread safety... There isn't one, apparently under the concurrent data structures... Has anyone seen one floating around? I've seen a java one implemented in amino-cbbs , called LockFreeVector but nothing for .NET so far. Any ideas? Well, I couldn't find such a class anywhere; so I gave it a shot . The source code for my ConcurrentList<T> class is available

boost c++ lock-free queue vs shared queue

两盒软妹~` 提交于 2019-12-02 18:33:50
I'm quite new in multithreading programming, I just know the most common Producer-Consumer-Queue. I'm using the boost c++ libraries and I don't know if is better use boost::lockfree::queue or a wrapper class around std::queue that is using `mutex` and `condition_variable`. Where is better using lock free data structures and where is better is use a simple implementation based on `mutex` and `condition_variables`? Try both in your app, see which performs best. Typically, polling a lock-free queue works best when the queue nearly always has entries, a blocking queue works best when the queue is

Understanding CLR 2.0 Memory Model

倖福魔咒の 提交于 2019-12-02 18:27:25
Joe Duffy, gives 6 rules that describe the CLR 2.0+ memory model (it's actual implementation, not any ECMA standard) I'm writing down my attempt at figuring this out, mostly as a way of rubber ducking, but if I make a mistake in my logic, at least someone here will be able to catch it before it causes me grief. Rule 1: Data dependence among loads and stores is never violated. Rule 2: All stores have release semantics, i.e. no load or store may move after one. Rule 3: All volatile loads are acquire, i.e. no load or store may move before one. Rule 4: No loads and stores may ever cross a full

Lock-free swap of two unique_ptr<T>

為{幸葍}努か 提交于 2019-12-02 17:26:55
Swapping two unique_ptr s is not guaranteed to be threadsafe. std::unique_ptr<T> a, b; std::swap(a, b); // not threadsafe Since I need atomic pointer swaps and since I like the ownership handling of unique_ptr , is there a simple way to combine them both? Edit: If this is not possible, I am open for alternatives. I at least want to do something like this: threadshared_unique_ptr<T> global; void f() { threadlocal_unique_ptr<T> local(new T(...)); local.swap_content(global); // atomically for global } What is the idiomatic way of doing this in C++11? Stas Lock-free swapping of two pointers It

Memory barriers in userspace? (Linux, x86-64)

痞子三分冷 提交于 2019-12-02 17:22:00
It is easy to set memory barriers on the kernel side: the macros mb, wmb, rmb, etc. are always in place thanks to the Linux kernel headers. How to accomplish this on the user side? Posix defines a number of functions as acting as memory barriers. Memory locations must not be concurrently accessed; to prevent this, use synchronization - and that synchronization will also work as a barrier. You are looking for the full memory barrier atomic builtins of gcc. Please note the detail on the reference i gave here says, The [following] builtins are intended to be compatible with those described in the

When are lock free data structures less performant than mutual exclusion (mutexes)?

孤者浪人 提交于 2019-12-02 16:23:52
I read somewhere (can't find the page anymore) that lock free data structures are more efficient "for certain workloads" which seems to imply that sometimes they're actually slower or the gain from them can be zero in some situations. Taking the ~100 cycle hit of a lock instruction to do an atomic op sounds plenty faster to me than going to sleep and waiting for the scheduler to wake the process back up, so it's not obvious to me under what circumstances a lock free data structure would be less preferable than old fashioned mutexes. If the lock is available 99% of the time and the process

How can I verify lock-free algorithms?

≯℡__Kan透↙ 提交于 2019-12-02 14:42:06
In theory, it should be possible to at least brute force a verification of a lock-free algorithm (there are only so many combinations of function calls intersecting). Are there any tools or formal reasoning processes available to actually prove that a lock-free algorithm is correct (ideally it should also be able to check for race conditions and the ABA problem as well)? Note: If you know a way to just prove one point (e.g. only prove that it is safe from the ABA problem) or a problem I haven't mentioned then post the solution anyway. In the worst case scenario, each method can be done in turn

How to implement lock-free skip list

半腔热情 提交于 2019-12-02 14:32:10
I need to implement a lock-free skip list. I tried to look for papers. Unfortunatly all I found was lock-free single linked lists (in many flavors). However how to implement lock-free skip list? ire_and_curses Lock-free skip lists are described in the book The Art of Multiprocessor Programming , and the technical report Practical lock-freedom , which is based on a PhD thesis on the subject. The skip list discussion begins on page 53. An example implementation, based on these sources, is included in this google code project . There are related discussions, links to literature and