memory-model

What is the (slight) difference on the relaxing atomic rules?

守給你的承諾、 提交于 2020-08-25 10:30:06
问题 After seeing Herb Sutters excellent talk about "atomic weapons" I got a bit confused about the Relaxed Atomics examples. I took with me that an atomic in the C++ Memory Model (SC-DRF = Sequentially Consistent for Data Race Free) does an "acquire" on a load/read. I understand that for a load [and a store] the default is std::memory_order_seq_cst and therefore the two are the same: myatomic.load(); // (1) myatomic.load(std::memory_order_seq_cst); // (2) So far so good, no Relaxed Atomics

Do async and await produce acquire and release semantics?

守給你的承諾、 提交于 2020-08-10 05:29:05
问题 I couldn't find a clear answer about whether returning from an async method always produces release semantics and whether await always produces acquire semantics. I assume yes, because otherwise any async/await code would be a minefield? So here's an example: are returned values both guaranteed to be 100*2 and 12345*2 , without any explicit locks or barriers? private static async Task<(int, int)> AMethod() { // Runs on the original thread: var x = 100; var y = 12345; var task = Task.Run(() =>

How to use Intel TSX with C++ memory model?

*爱你&永不变心* 提交于 2020-08-04 05:30:07
问题 I think C++ does not cover any sort of transaction memory yet, but still TSX can somehow fit using " as if rule" into something that is governed by C++ memory model. So, what happens on successful HLE operation, or successful RTM transaction? Saying "there is data race, but it is ok" is not much helpful, as it does not clarify what "ok" means. With HLE probably it can be seen as "previous operation happens before subsequent operation. As if the section was still guarded by the lock that was

C++11: the difference between memory_order_relaxed and memory_order_consume

我只是一个虾纸丫 提交于 2020-06-24 05:16:49
问题 I am now learning C++11 memory order model and would like to understand the difference between memory_order_relaxed and memory_order_consume . To be specific, I am looking for a simple example where one cannot replace memory_order_consume with memory_order_relaxed . There is an excellent post which elaborates on a simple yet very illustrative example where memory_order_consume can be applied. Below is literal copy-paste. Example: atomic<int*> Guard(nullptr); int Payload = 0; Producer: Payload

Why are Python integers implemented as objects?

半腔热情 提交于 2020-06-17 15:51:25
问题 Why are Python integers implemented as objects? The article Why Python is Slow: Looking Under the Hood as well as its comments contain useful information about the Python memory model and its ramifications, in particular wrt to performance. But this article does not ask or answer the question why the decision to implement integers as objects was made in the first place. In particular, referring to Python as dynamically typed is not an answer. It is possible to implement integers as integers