lockless

SpinWait in lockless update

喜夏-厌秋 提交于 2019-12-05 21:24:20
While reading Albahari's Threading in C# , I've noticed that the "lock free update" pattern uses a SpinWait at the end of the cycle: static void LockFreeUpdate<T> (ref T field, Func <T, T> updateFunction) where T : class { var spinWait = new SpinWait(); while (true) { // read T snapshot1 = field; // apply transformation T calc = updateFunction (snapshot1); // compare if not preempted T snapshot2 = Interlocked.CompareExchange (ref field, calc, snapshot1); // if succeeded, we're done if (snapshot1 == snapshot2) return; // otherwise spin spinWait.SpinOnce(); } } Note the spinWait.SpinOnce() call

Implementing a lock-free queue (for a Logger component)

自古美人都是妖i 提交于 2019-12-04 17:52:06
I am designing a new improved Logger component (.NET 3.5, C#). I would like to use a lock-free implementation. Logging events will be sent from (potentially) multiple threads, although only a single thread will do the actual output to file/other storage medium. In essence, all the writers are * enqueuing* their data into some queue, to be retrieves by some other process (LogFileWriter). Can this be achieved in a lock-less manner? i could not find a direct reference to this particular problem on the net. If you find that using a lock in this case is too slow, you have a much bigger problem. A

What's the difference between lockless and lockfree?

无人久伴 提交于 2019-11-30 16:56:01
问题 In some articles about algorithm, some use the word lockfree , and some use lockless . What's the difference between lockless and lockfree ? Thanks! Update http://www.intel.com/content/dam/www/public/us/en/documents/guides/intel-dpdk-programmers-guide.pdf section 5.2 --"Lockless Ring Buffer in Linux*", it's a example of use word "lockless" 回答1: An algorithm is lock-free if it satisfies that when the program threads are run sufficiently long at least one of the threads makes progress (for some

If I don't use fences, how long could it take a core to see another core's writes?

岁酱吖の 提交于 2019-11-29 04:23:44
I have been trying to Google my question but I honestly don't know how to succinctly state the question. Suppose I have two threads in a multi-core Intel system. These threads are running on the same NUMA node. Suppose thread 1 writes to X once, then only reads it occasionally moving forward. Suppose further that, among other things, thread 2 reads X continuously. If I don't use a memory fence, how long could it be between thread 1 writing X and thread 2 seeing the updated value? I understand that the write of X will go to the store buffer and from there to the cache, at which point MESIF will

How do I build a lockless queue?

ε祈祈猫儿з 提交于 2019-11-28 21:25:49
问题 I've spent today looking into lockless queues. I have a multiple producer, multiple consumer situation. I implemented, for testing, a system using the Interlocked SList thing under Win32 and it doubled the performance of my heavily threaded task based code. Unfortunately, though, I wish to support multiple platforms. Interlocking on multiple platforms itself is not a problem and I can safely assume I can interlock without problems. However the actual implementation loses me. The big problem

If I don't use fences, how long could it take a core to see another core's writes?

淺唱寂寞╮ 提交于 2019-11-27 15:09:10
问题 I have been trying to Google my question but I honestly don't know how to succinctly state the question. Suppose I have two threads in a multi-core Intel system. These threads are running on the same NUMA node. Suppose thread 1 writes to X once, then only reads it occasionally moving forward. Suppose further that, among other things, thread 2 reads X continuously. If I don't use a memory fence, how long could it be between thread 1 writing X and thread 2 seeing the updated value? I understand

How can I implement ABA counter with c++11 CAS?

不想你离开。 提交于 2019-11-26 01:08:59
问题 I am implementing a lock-free queue based on this algorithm, which uses a counter to solve the ABA problem. But I don\'t know how to implement this counter with c++11 CAS. For example, from the algorithm: E9: if CAS(&tail.ptr->next, next, <node, next.count+1>) It is an atomic operation, meaning if tail.ptr->next is equal to next , let tail.ptr->next point to node and simultaneously (atomically) make next.count+1 . However, using C++11 CAS, I can only implement: std::atomic_compare_exchange