memory-barriers Questions
4
This is more of a theoretical question. I'm not sure if all concepts, compiler behaviors, etc. are uptodate and still in use, but I'd like to have confirmation if I'm correctly understanding some c...
Simonette asked 23/4, 2016 at 13:22
3
Solved
Consider the following code:
#include <atomic>
#include <thread>
#include <cassert>
#include <memory>
int i = 0;
std::atomic_int a{0};
int main()
{
std::thread thr1{[]
{...
Calque asked 7/6 at 10:37
4
Solved
Condition variables are generally used such that the state they refer to is modified under a mutex. However, when the state is just a single set-only flag, there's no need for a mutex to prevent si...
Interglacial asked 29/8, 2011 at 19:29
1
Solved
libc++ std::counting_semaphore uses atomic increment with memory_order_release in release method:
void release(ptrdiff_t __update = 1)
{
if(0 < __a.fetch_add(__update, memory_order_release))
...
Cascade asked 2/8, 2020 at 11:27
3
Solved
I have read Intel 64 and IA-32 Architectures SDM vol 3A, 9.2 MEMORY ORDERING, but there was one question that kept bothering me.
If I first write to a memory address, then send an interprocessor in...
Nalor asked 28/5, 2023 at 18:8
2
To write a ref-counted class, I have seen 2 different approaches:
Approach 1:
struct RefCounting1 {
void ref_up() {
m_ref.fetch_add(1, std::memory_order_relaxed);
}
void release() {
if (m_ref...
Headman asked 27/2, 2023 at 20:46
1
Solved
Just when I thought I got some grip around atomics, I see another article. This is an excerpt from GCC wiki, under Overall Summary:
-Thread 1- -Thread 2- -Thread 3-
y.store (20); if (x.load() == ...
Reeducate asked 11/2, 2023 at 18:16
1
In Paul McKenny's famous paper "Memory Barriers: A Hardware View for Software Hackers"
3.3 Store Buffers and Memory Barriers
To see the second complication, a violation of global
memory ...
Dutiable asked 6/12, 2022 at 6:41
2
Consider an atomic read-modify-write operation such as x.exchange(..., std::memory_order_acq_rel). For purposes of ordering with respect to loads and stores to other objects, is this treated as:
a...
Disentomb asked 4/1, 2021 at 18:50
0
In MESI protocol you write to the cache line only when holding it in the Exclusive/Modified state. To acquire the Exclusive state, you send an Invalidate request to all the cores holding the same c...
Ritual asked 27/8, 2022 at 6:48
1
Solved
I came across this code for a simple implementation of a barrier (for code that can't use std::experimental::barrier in C++17 or std::barrier in C++20) in C++ Concurrency in Action book.
[Edit]
A b...
Tightrope asked 15/8, 2022 at 4:33
3
Solved
I keep fighting to understand what VarHandle::setOpaque and VarHandle::getOpaque are really doing. It has not been easy so far - there are some things I think I get (but will not present them in th...
Wheels asked 28/5, 2019 at 12:19
0
For example, functions like futex_wake/futex_wait, epoll_ctl/epoll_wait, pthread_create provide acquire/release semantics. That's to say, I made some changes before calling futex_wake, and then the...
Lynnett asked 25/7, 2022 at 12:42
2
So I have a simple cow_ptr. It looks something like this:
template<class T, class Base=std::shared_ptr<T const>>
struct cow_ptr:private Base{
using Base::operator*;
using Base::opera...
Bluhm asked 12/10, 2017 at 2:35
1
Solved
Consider following toy example, especially the result function:
#include <atomic>
#include <chrono>
#include <iostream>
#include <thread>
class Worker
{
std::thread th;
s...
Gley asked 13/6, 2022 at 17:32
0
Here is a simple example of acquire-release semantics used for data synchronization across threads.
// thread 1 // thread 2
data = 100;
flag.store(true, std::memory_order_release);
while(!flag.loa...
Anabolism asked 16/7, 2022 at 13:5
1
Solved
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 th...
Narcis asked 6/7, 2022 at 19:13
0
libc++ shared_ptr implementation release() for the sake of simplicity can be depicted as:
void release()
{
if (ref_count.fetch_sub(1, std::memory_order_acq_rel) == 1)
{
delete this;
}
}
Why do...
Selena asked 17/6, 2022 at 14:42
1
Solved
I know store buffer and invalidate queues are reasons that cause memory reordering. What I don't know is if Out-of-Order-Execution can cause memory reordering.
In my opinion, Out-of-Order-Execution...
Bailee asked 6/4, 2022 at 14:32
4
Solved
I am currently reading C++ Concurrency in Action by Anthony Williams. One of his listing shows this code, and he states that the assertion that z != 0 can fire.
#include <atomic>
#include &...
Fishman asked 22/1, 2018 at 14:31
2
Solved
I have a ring buffer that looks like:
template<class T>
class RingBuffer {
public:
bool Publish();
bool Consume(T& value);
bool IsEmpty(std::size_t head, std::size_t tail);
bool I...
Talca asked 28/12, 2021 at 20:51
1
Solved
I'm learning about different memory orders.
I have this code, which works and passes GCC's and Clang's thread sanitizers:
#include <atomic>
#include <iostream>
#include <future>
...
Aloysius asked 31/12, 2021 at 13:59
1
Solved
I read about Herb's atomic<> Weapons talk and had a question about page 42:
He mentioned that (50:00 in the video):
(x86) stores are much stronger than they need to be...
What I don't unde...
Frambesia asked 6/12, 2021 at 17:43
1
Solved
Consider the store buffer litmus test with SC atomics:
// Initial
std::atomic<int> x(0), y(0);
// Thread 1 // Thread 2
x.store(1); y.store(1);
auto r1 = y.load(); auto r2 = x.load();
Can th...
Hob asked 2/12, 2021 at 18:7
3
Solved
My understanding of std::memory_order_acquire and std::memory_order_release is as follows:
Acquire means that no memory accesses which appear after the acquire fence can be reordered to before the...
Sequestered asked 24/4, 2016 at 15:1
1 Next >
© 2022 - 2024 — McMap. All rights reserved.