C++98 中有哪些内存屏障?
What memory barriers are there in C++98?
我无意中发现了这个话题:Why is volatile not considered useful in multithreaded C or C++ programming?
并在投票最高的答案中偶然发现了以下内容...
However, memory barriers also ensure that all pending reads/writes are executed when the barrier is reached, so it effectively gives us everything we need by itself, making volatile unnecessary. We can just remove the volatile qualifier entirely.
Since C++11, atomic variables (std::atomic) give us all of the relevant guarantees.
我正在开发支持 C++98 的平台,那么 C++98 有哪些内存屏障可用?我曾尝试对 mbed 使用互斥锁,但我无法从逻辑上确定互斥锁是否足以保护例如在两个同时线程中发生的串行写入和读取,因为我没有足够的信心关于线程安全。
在 c++98 中访问简单共享资源的简单方法是什么?
C++98 标准是单线程的(不存在线程),因此在标准中 none。但是,您将有 OS/Platform 个特定的内存障碍。
but I can't logically determine if a mutex is a sufficient way to
protect, for example, both a serial write and read happening in two
simultaneous threads
如果互斥锁代码不能保证这一点,那么根据定义它们就被破坏了。我们必须查看该代码以检查它是否正确完成。
我无意中发现了这个话题:Why is volatile not considered useful in multithreaded C or C++ programming?
并在投票最高的答案中偶然发现了以下内容...
However, memory barriers also ensure that all pending reads/writes are executed when the barrier is reached, so it effectively gives us everything we need by itself, making volatile unnecessary. We can just remove the volatile qualifier entirely.
Since C++11, atomic variables (std::atomic) give us all of the relevant guarantees.
我正在开发支持 C++98 的平台,那么 C++98 有哪些内存屏障可用?我曾尝试对 mbed 使用互斥锁,但我无法从逻辑上确定互斥锁是否足以保护例如在两个同时线程中发生的串行写入和读取,因为我没有足够的信心关于线程安全。
在 c++98 中访问简单共享资源的简单方法是什么?
C++98 标准是单线程的(不存在线程),因此在标准中 none。但是,您将有 OS/Platform 个特定的内存障碍。
but I can't logically determine if a mutex is a sufficient way to protect, for example, both a serial write and read happening in two simultaneous threads
如果互斥锁代码不能保证这一点,那么根据定义它们就被破坏了。我们必须查看该代码以检查它是否正确完成。