Skip to main content
Filter by
Sorted by
Tagged with
3 votes
2 answers
163 views

I'm reading this: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3292r0.html Here's code sample the question is about: int dummy; std::atomic<int *> ptr_to_int_1{&dummy}; std::...
De Cay's user avatar
  • 34
0 votes
0 answers
72 views

In the idiom: while (exp == V.loadRelaxed()) { // allows the early issuing of any n-loads that'd fit within the speculative window. if (V.weakRMWRelease(exp, set)) return true; // ^^ (upward ...
Delark's user avatar
  • 1,385
0 votes
0 answers
53 views

I was wondering about what the consequences of a relaxed load in a while loop would be, and if it would be sufficient fencing. My question arises from the fact that the Java community has agreed that &...
Delark's user avatar
  • 1,385
1 vote
0 answers
88 views

I have a thread pool implementation, which stops all threads by setting a special atomic bool stop to true. Its destructor looks like this: ThreadPool::~ThreadPool() { stop.store(true); for (...
Artegful's user avatar
0 votes
2 answers
227 views

I was testing the behavior of the control dependencies in LINUX KERNEL MEMORY BARRIERS, and had a problem with the location of the fence. I was testing this on AArch64 on a Qualcomm Snapdragon 835, ...
Kymdon's user avatar
  • 13
1 vote
1 answer
92 views

Consider this code in C#: private int _backingField; public int SomeNumber => Volatile.Read(ref _backingField); public void Test_1() { var someNumber = Volatile.Read(ref _backingField); /...
user3163495's user avatar
  • 3,968
0 votes
0 answers
23 views

public class Cache_01_Sample { @JCStressTest @Outcome(expect = ACCEPTABLE, desc = "9") @Outcome(id = "-1", expect = FORBIDDEN, desc = "0") @State ...
刘警君's user avatar
1 vote
0 answers
96 views

I am using a seq_lock for coordination between a reader and a writer thread. The reader calls load(), and the writer calls store(). Here's a simplified version of my code: #include <atomic> #...
user avatar
-1 votes
2 answers
134 views

I'm working with atomic operations in a multi-threaded program in C++ and trying to understand how acquire semantics behave when used without a corresponding release. Specifically, I know that acquire ...
user avatar
1 vote
1 answer
343 views

I'm going through Mara's Atomics and locks book, which shows this example code where it assumes that the function a and b are executed concurrently: static X: AtomicI32 = AtomicI32::new(0); fn a() { ...
Sibi's user avatar
  • 49k
1 vote
0 answers
107 views

I thought typically memory barriers can be categorized into four types. Some of the barriers include multiple functions. For example, StoreLoad can both prevent reordering between store and load, and ...
Xavier Z's user avatar
  • 402
0 votes
0 answers
142 views

Is there a standard way to prevent code reordering when profiling functions in c++? Let's say I have a code like this void foo() { const auto timeStart = std::chrono::system_clock::now(); // ...
DDG's user avatar
  • 171
0 votes
0 answers
17 views

I have 2 threads running after write_fd was initialized by a call to pipe(): static bool finished = false; Thread 1 pthread_mutex_lock(&lock); if (!finished) { write(write_fd, buf, buf_len); }...
Itay Bianco's user avatar
0 votes
0 answers
129 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
2 votes
1 answer
126 views

This is my code: Godbolt. #include <atomic> #include <iostream> #include <thread> #include <vector> int main(int, char **) { volatile bool resource = true; std::...
Monte's user avatar
  • 49
1 vote
2 answers
458 views

Why does this kind of code crash (very occasionally!) on x64? class Object { public: void manipulate(); // reads and writes object bool m_finished = false; // note this is a regular bool and ...
Dave Poston's user avatar
1 vote
1 answer
441 views

As per my current understanding from the ARM Cortex A57 and A78 TRM, micro ops can be issued out of order to 1 among the several execution pipelines. This is instruction reordering for independent ...
Shaibal's user avatar
  • 925
1 vote
1 answer
419 views

I am new to C++. When I debugged in Clion, I found that the execution order using Step over (F8) doesn't match the real code's order. So far, I think the most possible reason is compiler optimization. ...
Yang Xu's user avatar
  • 65
10 votes
1 answer
663 views

I have read about std::memory_order in C++ and understood partially. But I still had some doubts around it. Explanation on std::memory_order_acquire says that, no reads or writes in the current ...
Sourav Kannantha B's user avatar
0 votes
0 answers
32 views

In the context of out of order and dynamic scheduling in the topic of computer architecture, why do store instructions have to wait until they are committed (retired) before they modify memory? I ...
Mahmoud Mousa Hamad's user avatar
1 vote
2 answers
102 views

I have the following C# algorithm for config file writeback: string strPathConfigFile = "C:\File.txt" string strPathBackupFile = "C:\File.backup" string strContent = "File ...
TostMaster's user avatar
1 vote
0 answers
161 views

My multithreaded code is as follows: thread A while(true) { foo(); sleep(); } thread B ... bar_off(); bar_on(); ... foo() isn't safe to be executed when bar_off is called and until bar_on has ...
Lolo's user avatar
  • 4,219
5 votes
1 answer
690 views

Given: std::atomic<uint64_t> b; void f() { std::atomic_thread_fence(std::memory_order::memory_order_acquire); uint64_t a = b.load(std::memory_order::memory_order_acquire); // code ...
Joseph Garvin's user avatar
5 votes
1 answer
562 views

Given: std::atomic<uint64_t> x; uint64_t f() { x.store(20, std::memory_order::memory_order_relaxed); x.store(10, std::memory_order::memory_order_relaxed); return x.load(std::...
Joseph Garvin's user avatar
1 vote
2 answers
113 views

Because ordinary reading and writing after volatile writing does not prohibit reordering, may b=3 in the following code be reordered before a=2+b? volatile int a = 1; int b = 2; private void demo () {...
嘉图李's user avatar
1 vote
1 answer
700 views

This is a follow up question to How to demonstrate Java instruction reordering problems? There are many articles and blogs referring to Java and JVM instruction reordering which may lead to counter-...
Gonen I's user avatar
  • 6,187
0 votes
1 answer
180 views

I'm trying to understand why a shared CancellationTokenSource variable is not protected by a lock or memory barriers here. I know there is a rule of thumb that a read or a write of a shared (state) ...
bimjhi's user avatar
  • 311
6 votes
1 answer
2k views

I'm trying to understand exactly how Google's DoNotOptimize() is supposed to work. For completeness, here is its definition (for clang, and non-const data): template <class Tp> inline ...
Edd Barrett's user avatar
  • 3,685
0 votes
1 answer
2k views

I'm struggling to understand the difference between data dependence and control dependence . So what I saw as an example was : data dependence e.g., instruction uses data created by another ...
Hai Dvash's user avatar
0 votes
1 answer
263 views

Since rust applies the mutex as a container/owner of its data and doesn't use an external guard like C++, I was wondering whether the rust compiler might reorder the internal part of the loop in the ...
Adam's user avatar
  • 915
1 vote
1 answer
217 views

I tried to implement Peterson Lock with C# like this public class PetersonLock { private volatile bool[] flag = new bool[2]; private volatile int victim; public int oneThreadId; ...
WardenAllen's user avatar
1 vote
0 answers
199 views

As we know, the compiler or the CPU may reorder the execution as they want, only if they follow the as-if rule. For example, if we have such a piece of code: C = A + B; D = E + F; The compiler or the ...
Yves's user avatar
  • 12.6k
1 vote
1 answer
152 views

As we know, the compiler or the CPU may reorder the execution as they want, only if they follow the as-if rule. For example, if we have such a piece of code: C = A + B; D = E + F; The compiler or the ...
Yves's user avatar
  • 12.6k
2 votes
0 answers
112 views

The following code is a struct I have written to allow me to queue up work to run on multiple worker threads, and which blocks the main thread until a new worker thread is available. struct WorkQueue{ ...
Ben's user avatar
  • 490
3 votes
2 answers
226 views

Below code sample is taken from JLS 17.5 "final Field Semantics": class FinalFieldExample { final int x; int y; static FinalFieldExample f; public FinalFieldExample() { x = ...
Nikita Tkachenko's user avatar
3 votes
3 answers
1k views

From very nice Paper and article about memory reordering. Q1: I understand that cache-coherence, store buffer and invalidation queue is root cause of memory reordering ? Store release is quite ...
LongLT's user avatar
  • 442
0 votes
2 answers
433 views

Now we have Load A StoreStore Store B Is it possible that the actual execution order is as follows StoreStore Store B Load A If it is possible, how to explain a situation which seems to violate the ...
user2351281's user avatar
1 vote
2 answers
398 views

So, I was reading a lot about instruction and memory reordering and how we can prevent it, but i still have no answer to one qustion (probably because I'm not attentive enough). My question is: Do we ...
IgnatiusPo's user avatar
1 vote
1 answer
80 views

I have this array that is the correct order: $orderDoc = array("ORT", "TRI", "CONT", "RMI"); These documents are in different tables of several servers and database. At the end of doing the search of ...
user avatar
1 vote
1 answer
202 views

When I am suspicious certain instruction reordering is allowed by the java language specification, I want to reproduce it in a jcstress test. How can I do that? For example, in the following code, the ...
user675693's user avatar
2 votes
1 answer
106 views

Iam wondering if its possible that the initialvalue in the following code can be reordered to be after the computation resulting in undefined behavior. The following example is taken from https://...
Barsonax's user avatar
  • 310
0 votes
1 answer
99 views

In Linux Kernel Development (3rd Edition), Kernel Synchronization Methods, Ordering and Barriers. There is an example: And I'm confused about the statement in this book: Again, without memory ...
cong's user avatar
  • 1,197
6 votes
1 answer
2k views

OK, so a compiler is free to reorder code fragments for performance reasons. Let's suppose some code snippet, translated directly into machine code with no optimizations applied, looks like this: ...
Peter's user avatar
  • 385
46 votes
3 answers
3k views

With Java instruction reordering the execution order of the code is changed by the JVM at compile time or run time, possibly causing unrelated statements to be executed out-of-order. Edit: [...
Gonen I's user avatar
  • 6,187
7 votes
3 answers
549 views

from http://en.cppreference.com : Relaxed ordering Atomic operations tagged std::memory_order_relaxed are not synchronization operations, they do not order memory. They only guarantee atomicity and ...
Guillaume Paris's user avatar