c++, std::atomic, what is std::memory_order and how to use them?

The std::memory_order values allow you to specify fine-grained constraints on the memory ordering provided by your atomic operations. If you are modifying and accessing atomic variables from multiple threads, then passing the std::memory_order values to your operations allow you to relax the constraints on the compiler and processor about the order in which the operations … Read more

What operations in Java are considered atomic?

all assignments of primitive types except for long and double all assignments of references all assignments of volatile variables all operations of java.concurrent.Atomic* classes and maybe something more. Look at the jls. As noted in the comments, atomicity does not imply visibility. So while another thread is guaranteed not to see a partially written int, … Read more

Which is more efficient, basic mutex lock or atomic integer?

Atomic operations leverage processor support (compare and swap instructions) and don’t use locks at all, whereas locks are more OS-dependent and perform differently on, for example, Win and Linux. Locks actually suspend thread execution, freeing up cpu resources for other tasks, but incurring in obvious context-switching overhead when stopping/restarting the thread. On the contrary, threads … Read more

When do I really need to use atomic instead of bool? [duplicate]

No type in C++ is “atomic by nature” unless it is an std::atomic*-something. That’s because the standard says so. In practice, the actual hardware instructions that are emitted to manipulate an std::atomic<bool> may (or may not) be the same as those for an ordinary bool, but being atomic is a larger concept with wider ramifications … Read more

reference assignment is atomic so why is Interlocked.Exchange(ref Object, Object) needed?

There are numerous questions here. Considering them one at a time: reference assignment is atomic so why is Interlocked.Exchange(ref Object, Object) needed? Reference assignment is atomic. Interlocked.Exchange does not do only reference assignment. It does a read of the current value of a variable, stashes away the old value, and assigns the new value to … Read more

What is the difference between atomic and critical in OpenMP?

The effect on g_qCount is the same, but what’s done is different. An OpenMP critical section is completely general – it can surround any arbitrary block of code. You pay for that generality, however, by incurring significant overhead every time a thread enters and exits the critical section (on top of the inherent cost of … Read more

Is file append atomic in UNIX?

A write that’s under the size of ‘PIPE_BUF’ is supposed to be atomic. That should be at least 512 bytes, though it could easily be larger (linux seems to have it set to 4096). This assume that you’re talking all fully POSIX-compliant components. For instance, this isn’t true on NFS. But assuming you write to … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)