memory-model Questions
1
In the example of boost::atomic, the unref function:
void intrusive_ptr_release(const X * x)
{
if (x->refcount_.fetch_sub(1, boost::memory_order_release) == 1) {
boost::atomic_thread_fence(bo...
Letishaletitia asked 14/8, 2014 at 9:6
1
Solved
My understanding is that a spinlock can be implemented using C++11 atomics with
an acquire-CAS on lock and a release-store on unlock, something like this:
class SpinLock {
public:
void Lock() {
...
Snowblind asked 23/7, 2014 at 4:17
2
Solved
we all know the idea of stack and heap, but I recently read about a third option to save data: registers.
I have a hard time finding good articles about this type, what I found was: http://www.dot...
Snub asked 13/6, 2014 at 10:55
2
Solved
I read this in an upvoted comment on StackOverflow:
But if you want to be safe, you can add simple synchronized(this) {}
at the end of you @PostConstruct [method]
[note that variables were NO...
Farver asked 28/5, 2014 at 8:43
2
Consider the following pseudocode:
expected = null;
if (variable == expected)
{
atomic_compare_exchange_strong(
&variable, expected, desired(), memory_order_acq_rel, memory_order_acq);
}
ret...
Luminance asked 1/5, 2014 at 9:37
3
Solved
I have a program which spawns multiple threads that may write the exact same value to the exact same memory location:
std::vector<int> vec(32, 1); // Initialize vec with 32 times 1
std::vect...
Dobbins asked 13/4, 2014 at 13:21
2
Solved
The following pattern is commonplace in lots of software that wants to tell its user how many times it has done various things:
int num_times_done_it; // global
void doit() {
++num_times_done_it...
Gennygeno asked 11/4, 2014 at 4:58
2
Solved
In the following simple scenario:
class A {
int x;
Object lock;
...
public void method(){
synchronized(lock){
// modify/read x and act upon its value
}
}
}
Does x need to be volatile? ...
Flex asked 4/4, 2014 at 12:0
1
In the Linux kernel spinlock implementation for the TILE-Gx architecture, it looks like they don't issue any memory barriers when locking (only when unlocking):
https://github.com/torvalds/linux/b...
Laser asked 12/12, 2013 at 17:14
1
Solved
Loop hoisting a volatile read
I have read many places that a volatile variable can not be hoisted from a loop or if, but I cannot find this mentioned any places in the C# spec. Is this a hidden fe...
Egis asked 24/2, 2014 at 13:52
2
Solved
Can someone explain it in a language that mere mortals understand?
Sturges asked 20/6, 2011 at 12:39
2
Basically I have trouble understanding this: (from Bjarne FAQ)
However, most modern processors cannot read or write a single
character, it must read or write a whole word, so the assignment to ...
Felly asked 11/11, 2013 at 9:52
3
Solved
I've been reading about the new C++11 memory model and I've come upon the std::kill_dependency function (§29.3/14-15). I'm struggling to understand why I would ever want to use it.
I found an...
Neeley asked 22/8, 2011 at 16:16
3
I am reading C++ Concurrency in Action by Anthony Williams. Currently I at point where he desribes memory_order_consume.
After that block there is:
Now that I’ve covered the basics of the memor...
Foretopmast asked 8/2, 2013 at 19:0
3
Solved
std::atomic functions such as store and load take an std::memory_order argument. The argument can be determined at runtime, like any other function argument. However, the actual value may effect th...
Columba asked 18/12, 2012 at 20:40
1
Solved
Assume you've got the following definitions:
struct X
{
char a, b;
};
X x;
And now assume you have two threads, one of which reads and writes x.a but never accesses x.b while the other one rea...
Shealy asked 18/8, 2013 at 20:12
1
Solved
This question is in reference to memory visibility only, not happens-before and happens-after. There are four ways in Java that guarantees changes to memory in one thread to be made visible to anot...
Dinner asked 11/6, 2013 at 2:4
1
Solved
I understand that in sequential consistency all processes have to be processed sequentially. For example:
Process 1 Process 2
x = 1 z = 5
y = 2 p = 3
So, we can get x=1, z=5, y=2, p=3 or z=5, p=...
Hexyl asked 4/6, 2013 at 23:59
1
Solved
http://en.cppreference.com/w/cpp/atomic/memory_order, and other C++11 online references, define memory_order_acquire and memory_order_release as:
Acquire operation: no reads in the current thread...
Contumely asked 23/4, 2013 at 22:2
1
Solved
I am reading the C++ memory model defined in n3485 and it talks about release/acquire semantics, which from what I understand, and also from the definitions given in this blog:
Acquire semantics i...
Diffident asked 9/3, 2013 at 16:48
1
Solved
I have seen that this question on acquire, release, consume, etc exists, however, no answer really defines what a "consume operation" actually is.
In 1.10 paragraph 5 it states:
A synchronizati...
Brenza asked 7/3, 2013 at 11:49
2
Solved
For any std::atomic<T> where T is a primitive type:
If I use std::memory_order_acq_rel for fetch_xxx operations, and std::memory_order_acquire for load operation and std::memory_order_releas...
Maltese asked 13/2, 2013 at 19:50
1
Solved
I am reading C++ Concurrency in Action by Anthony Williams.
At section "Understanding Relaxed Ordering" it has:
There are a few additional things you can tell the man in the cubicle, such as “wr...
Wilbur asked 10/2, 2013 at 5:49
1
Solved
Suppose I have a C++11 application where two threads write to different but nearby memory locations, using simple pointers to primitive types. Can I be sure that both these writes will end up in me...
Bumpy asked 1/2, 2013 at 6:58
1
Solved
According to the Java Language Specification (Example 17.4-1) the following snippet (starting in A == B == 0)...
Thread 1 Thread 2
-------- --------
r2 = A; r1 = B;
B = 1; A = 2;
... can result in...
Sublittoral asked 3/1, 2013 at 20:42
© 2022 - 2024 — McMap. All rights reserved.