lock-free

Dynamic Lock-free memory allocators

北城以北 提交于 2020-05-13 17:48:13
问题 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

Store an address and a bool in one word for lock-free doubly linked list

天大地大妈咪最大 提交于 2020-03-05 03:57:12
问题 I am reading some paper for lock-free doubly linked list. In these papers, they store an address to next and prev node and a flag in one word(int). Is it because in 32-bit architectures all addresses are aligned in 4 byte boundaries so all address are multiple of 4? and if the reason is what i say is this code ok? const int dMask = 1; const int pMask = ~dMask; int store(void* pPointer, bool pDel) { return reinterpret_cast<int>(pPointer) | (int)pDel; } void load(int pData, void** pPointer,

C# SemaphoreSlim array elements read/write synchronization [closed]

醉酒当歌 提交于 2020-03-04 20:05:42
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 days ago . My blocking ring queue don't use lock or Mutex , only two SemaphoreSlim (block than 0 and than max element, so write and read part of array never intersects) and two int indexes modified by Interlocked.Decrement (not determine write/read index, but make it unique and correct move).

C# SemaphoreSlim array elements read/write synchronization [closed]

末鹿安然 提交于 2020-03-04 20:05:13
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 days ago . My blocking ring queue don't use lock or Mutex , only two SemaphoreSlim (block than 0 and than max element, so write and read part of array never intersects) and two int indexes modified by Interlocked.Decrement (not determine write/read index, but make it unique and correct move).

C# SemaphoreSlim array elements read/write synchronization [closed]

大兔子大兔子 提交于 2020-03-04 20:05:11
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 days ago . My blocking ring queue don't use lock or Mutex , only two SemaphoreSlim (block than 0 and than max element, so write and read part of array never intersects) and two int indexes modified by Interlocked.Decrement (not determine write/read index, but make it unique and correct move).

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

烂漫一生 提交于 2020-01-27 04:18:13
问题 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

StoreStore reordering happens when compiling C++ for x86

大兔子大兔子 提交于 2020-01-25 20:40:48
问题 while(true) { int x(0), y(0); std::thread t0([&x, &y]() { x=1; y=3; }); std::thread t1([&x, &y]() { std::cout << "(" << y << ", " <<x <<")" << std::endl; }); t0.join(); t1.join(); } Firstly, I know that it is UB because of the data race. But, I expected only the following outputs: (3,1), (0,1), (0,0) I was convinced that it was not possible to get (3,0) , but I did. So I am confused- after all x86 doesn't allow StoreStore reordering. So x = 1 should be globally visible before y = 3 I suppose

Strange shared_ptr behaviour

微笑、不失礼 提交于 2020-01-13 11:39:18
问题 Ive discovered a really strange behaviour with std::shared_ptr in c++. The following example works perfectly with standard pointers. However the usage of std::shared_ptr causes here a segmentation fault. (see the backtrace below) I know, that accessing a std::shared_ptr from multiple threads is not safe, therefor I'm using the atomic-operations. Even a classic lock wont solve the problem. Im using gcc version 6.3.0 20170406 (Ubuntu 6.3.0-12ubuntu2) with -Wall -O2 -g and -std=c++17 Does

is_lock_free() returned false after upgrading to MacPorts gcc 7.3

别说谁变了你拦得住时间么 提交于 2020-01-10 05:05:26
问题 Previously, with Apple LLVM 9.1.0, is_lock_free() on 128-bit structures have returned true. To have complete std::optional support, I then upgraded to MacPorts gcc 7.3. During my first try to compile, I encountered this notorious showstopper linker error: Undefined symbols for architecture x86_64: "___atomic_compare_exchange_16", referenced from: I know that I may need to add -latomic . With Apple LLVM 9.1.0, I don't need it, and I have a very bad feeling about this. If it's lock-free, you

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

◇◆丶佛笑我妖孽 提交于 2020-01-09 06:50:05
问题 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