lock-free

Lockfree Read value after Interlocked.Exchange?

喜你入骨 提交于 2021-02-08 06:49:55
问题 Lets say we have a class like so: public class Foo { private Bar bar = new Bar(); public void DoStuffInThread1() { var old = Interlocked.Exchange(ref bar,new Bar()); //do things with old //everything is fine here, I'm sure I have the previous bar value } public void OtherStuffFromThread2() { //how do I ensure that I have the latest bar ref here //considering mem cahces etc bar.Something(); } } And lets say we have two threads, one operating on DoStuffInThread1 and another on

Lockfree Read value after Interlocked.Exchange?

若如初见. 提交于 2021-02-08 06:48:53
问题 Lets say we have a class like so: public class Foo { private Bar bar = new Bar(); public void DoStuffInThread1() { var old = Interlocked.Exchange(ref bar,new Bar()); //do things with old //everything is fine here, I'm sure I have the previous bar value } public void OtherStuffFromThread2() { //how do I ensure that I have the latest bar ref here //considering mem cahces etc bar.Something(); } } And lets say we have two threads, one operating on DoStuffInThread1 and another on

C++ Treiber Stack and atomic next pointers

为君一笑 提交于 2021-02-07 09:19:07
问题 The "Treiber Stack" is generally one of the simplest lock-free data structures, and so it is often used when teaching introductions to lock-free algorithms. I've seen many implementations of Treiber Stacks using C++ atomics. The algorithm itself is trivial, so the real challenge is handling all the other incidental details of lock-free data-structures, such as providing some way of performing safe memory reclamation, avoiding the ABA problem, and allocating nodes in a lock-free manner. This

Lock free synchronization

断了今生、忘了曾经 提交于 2020-12-01 10:46:11
问题 My question is related to multithreading lock-free synchronization. I wanted to know the following: What are general approaches to achieve this? I read somewhere about LockFreePrimitives like CompareAndExchange (CAS) or DoubleCompareAndExchange (DCA) but no explanation for those were given? Any approaches to MINIMIZE use of locks? How does Java/.NET achieve their concurrent containers? Do they use locks or lock-free synch? Thanks in advance. 回答1: Here are some general approaches that can

Why is a store-load barrier considered expensive?

不打扰是莪最后的温柔 提交于 2020-11-30 06:39:15
问题 Most CPU architectures will re-order stores-load operations, but my question is why? My interpretation of a store-load barrier would look like this: x = 50; store_load_barrier; y = z; Furthermore, I don't see how this barrier would be have much use in lock-free programming in comparison to release and acquire semantics. 回答1: Short Answer : The store-load barrier prevents the processor from speculatively executing LOAD that come after a store-load barrier until all previous stores have

Anything in std::atomic is wait-free?

狂风中的少年 提交于 2020-08-24 08:09:29
问题 If T is a C++ fundamental type, and if std::atomic<T>::is_lock_free() returns true , then is there anything in std::atomic<T> that is wait-free (not just lock-free)? Like, load , store , fetch_add , fetch_sub , compare_exchange_weak , and compare_exchange_strong . Can you also answer based on what is specified in the C++ Standard, and what is implemented in Clang and/or GCC (your version of choice). My favorite definitions for lock-free and wait-free are taken from C++ Concurrency in Action

A readers/writer lock… without having a lock for the readers?

我怕爱的太早我们不能终老 提交于 2020-05-15 04:56:26
问题 I get the feeling this may be a very general and common situation for which a well-known no-lock solution exists. In a nutshell, I'm hoping there's approach like a readers/writer lock, but that doesn't require the readers to acquire a lock and thus can be better average performance. Instead there'd be some atomic operations (128-bit CAS) for a reader, and a mutex for a writer. I'd have two copies of the data structure, a read-only one for the normally-successful queries, and an identical copy

A readers/writer lock… without having a lock for the readers?

杀马特。学长 韩版系。学妹 提交于 2020-05-15 04:54:18
问题 I get the feeling this may be a very general and common situation for which a well-known no-lock solution exists. In a nutshell, I'm hoping there's approach like a readers/writer lock, but that doesn't require the readers to acquire a lock and thus can be better average performance. Instead there'd be some atomic operations (128-bit CAS) for a reader, and a mutex for a writer. I'd have two copies of the data structure, a read-only one for the normally-successful queries, and an identical copy

Dynamic Lock-free memory allocators

一曲冷凌霜 提交于 2020-05-13 17:54:12
问题 One of the difficulties in writing algorithms or data structures that satisfy lock-free progress guarantees is dynamic memory allocation: calling something like malloc or new isn't guaranteed to be lock-free in a portable manner. However, many lock-free implementations of malloc or new exist, and there are also a variety of lock-free memory allocators that can be used to implement lock-free algorithms/data-structures. However, I still don't understand how this can actually completely satisfy

Dynamic Lock-free memory allocators

 ̄綄美尐妖づ 提交于 2020-05-13 17:49:12
问题 One of the difficulties in writing algorithms or data structures that satisfy lock-free progress guarantees is dynamic memory allocation: calling something like malloc or new isn't guaranteed to be lock-free in a portable manner. However, many lock-free implementations of malloc or new exist, and there are also a variety of lock-free memory allocators that can be used to implement lock-free algorithms/data-structures. However, I still don't understand how this can actually completely satisfy