Skip to main content
Filter by
Sorted by
Tagged with
0 votes
2 answers
121 views

I am trying to implement a lock-free multiple-producer-single-consumer ring buffer in C++. Here is the full definition and the test code. #include <iostream> #include <memory> #include <...
God_of_Thunder's user avatar
2 votes
1 answer
117 views

I'm trying to learn CUDA programming, and recently I have been working on the lectures in this course: https://people.maths.ox.ac.uk/~gilesm/cuda/lecs/lec3.pdf, where they discussed the atomicCAS ...
Dang Manh Truong's user avatar
0 votes
0 answers
99 views

I am trying to solve the much talked about problem of transferring money from one account to another in a thread safe manner, given that the accounts exist in memory only. I was able to easily solve ...
Murtaza Hasan's user avatar
-2 votes
1 answer
113 views

I am getting into a race condition with 2 threads while using atomic CAS. std::atomic<int> turn(0); int free = 0; void Work(int pid){ while(true){ if(turn.compare_exchange_strong(...
ssingla's user avatar
  • 39
5 votes
2 answers
148 views

I was learning about C++ memory sequence, and I found this code in Unreal Engine5. My question is why not call compare_exchange_strong() directly instead of load() first? FHttpRequest* GetFreeRequest()...
Fosky etm's user avatar
5 votes
0 answers
164 views

Consider the following interaction between T1 and T2. Can it happen that T2 will miss the notification from T1 and will suspend? In other words, can it happen that compare_exchange_weak will succeed ...
Roman's user avatar
  • 1,513
1 vote
1 answer
131 views

I have a block of code where std::atomic<std::weak_ptr<T>> doesn't behave the way I would have expected if the underlying weak pointer is expired: std::atomic<std::weak_ptr<Widget>...
GeoRanger's user avatar
0 votes
1 answer
140 views

After learning std::atomic and std::memory_order I wanted to experiment with writing a thread safe shared_ptr<T> and weak_ptr<T> implementation using atomics based on Microsoft Blog: ...
h243jian's user avatar
-4 votes
1 answer
560 views

I was trying to implement my own custom SpinLock, but the SpinLock seems to misbehave. I have two files, main.rs and safe.rs. The test was done in Ubuntu 22.04.3LTS and the system specs are 4GB RAM, ...
Lokesh's user avatar
  • 43
0 votes
0 answers
128 views

Could a memory write instruction (mov reg to memory) after cmpxchg (without lock prefix) be recordered and executed before cmpxchg for x86? EX1: // try_cmpxchg_local(&local.pos, &tail, ...
matt's user avatar
  • 101
0 votes
1 answer
514 views

My understanding is that compare-and-swap is something supported by hardware, e.g., CMPXCHG in x86 architecture. I have the following two confusions: Is it that C++'s atomic does not "implement&...
D.J. Elkind's user avatar
0 votes
1 answer
298 views

Hi I noticed that the CAS Compare-and-Swap operations are usually operated on atomic variables, see https://en.cppreference.com/w/cpp/atomic/atomic/compare_exchange, https://docs.oracle.com/javase/8/...
Dachuan Huang's user avatar
0 votes
1 answer
205 views

I don't know if bubble sort is optimal under the condition that only adjacent swaps are allowed? Is there a more optimal algorithm that can directly determine the parity of the minimum number of swaps ...
埃博拉酱's user avatar
0 votes
1 answer
542 views

I am trying to do a CAS with __sync_val_compare_and_swap in my eBPF code. As this operation needs to be atomic I cannot use bpf_probe_read_user. With a regular kernel variable ...
Victor's user avatar
  • 9
0 votes
0 answers
151 views

I'm using std::atomic to create a stack that utilizes CAS. To solve the ABA problem, I used tagged pointer. The code is shown below. template <typename T> union tagged_ptr { struct { ...
tongstar's user avatar
1 vote
1 answer
170 views

I am assuming that the piece of code is threadsafe, if ((Interlocked.CompareExchange(ref semaphore, 1, 0) == 0)) { //Do Stuff semaphore = 0; } However I am wondering why: In my mind I see this as ...
Somecode's user avatar
1 vote
1 answer
427 views

Is there any case where we'd want to load an atomic with memory_order_acquire without a corresponding store to the same atomic with memory_order_release? For example, if I have this piece of code: std:...
ktqq99's user avatar
  • 35
0 votes
1 answer
229 views

I came across this code emission for x64 were "Atomic Load" is using a simple movq whereas "Atomic Store" is using xchgq. This link explains that Atomic Load/Stores on aligned ...
Dan's user avatar
  • 3,068
0 votes
1 answer
86 views

I have a method that adds elements into a doubly linked list, and swaps elements into ascending order if the first element is greater than the second element. If I input 23, 24, 16, it skips swapping ...
Jax's user avatar
  • 1
0 votes
1 answer
184 views

Suppose I have some global: std::atomic_int next_free_block; and a number of threads each with access to a std::atomic_int child_offset; that may be shared between threads. I would like to allocate ...
konsolas's user avatar
  • 1,091
1 vote
1 answer
282 views

I'm trying to implement an atomic tagged/packed pointer, for the sake of learning. I want to use the upper 16 bits for a uint16_t counter, and the lower 3 bits for a 3-bit tag. So far, I've managed to ...
Gavin Ray's user avatar
  • 725
0 votes
1 answer
376 views

Assume we implement in a modern programming language like C++. Let's say we have 5 threads t1 to t5, and we also have an array of timestamps TS[5] one for each thread. We also have a global timestamp ...
libinzhou's user avatar
3 votes
1 answer
3k views

I'm trying to understand the 'Compare And Swap' operation, briefly called CAS. I found that it has a variant called 'Compare And Set'. They work the same way but the return is different. 'Compare And ...
taher bouali's user avatar
0 votes
1 answer
425 views

I've decided to implement some clasess from the concurrency package from scratch and implemented Semaphore with wait/notify. It seems very easy and intuitive to do so. When I checked the build in ...
Iaroslav Baranov's user avatar
1 vote
1 answer
807 views

In java 17, AtomicReference has the compareAndExchange method which is like compareAndSet, but instead of returning a boolean, it returns the value right before the atomic action. I need that to ...
李浩穎's user avatar

1
2 3 4 5
8