4,056 questions
1
vote
2
answers
272
views
Are the lock and unlock methods of a mutex object considered as modifications to the object?
[thread.mutex.requirements.mutex.general] p4 says
For purposes of determining the existence of a data race, these behave as atomic operations ([intro.multithread]). The lock and unlock operations on ...
4
votes
3
answers
299
views
Does std::atomic remain atomic when a struct is allocated with malloc?
I have a struct that contains a std::atomic member:
#include <atomic>
#include <cstdint>
struct Foo {
std::atomic<int64_t> value;
int64_t age;
};
If I allocate memory for ...
4
votes
0
answers
100
views
Clangd throw an error when passing a pointer to an atomic var to atomic macros in CLion
I can't find out why clangd (in CLion 2025.3) throw me an error when I write :
atomic_int foo;
atomic_init(&foo, 0);
Clangd: Incompatible pointer types passing 'typeof ((void)0 , *...
0
votes
1
answer
227
views
How to force evaluation of an always false function?
Have some multi-threaded code that needs to do some locking. The details of that do not matter here. But I do the canonical do { ... } while (!CAS) loop.
To keep the code concise I want to add a wait ...
4
votes
3
answers
265
views
Does the returned value from `std::steady_clock::now()` denote a point in global time of the program?
Consider this example:
#include <atomic>
#include <chrono>
#include <thread>
uint64_t timestamp() {
auto now = std::chrono::steady_clock::now().time_since_epoch();
return ...
2
votes
1
answer
66
views
Replacing atomic-polyfill::AtomicUsize::fetch_add with critical-section on thumbv6m-none-eabi
Platform: rp2040 (2 Cortex-M0+ cores, thumbv6m-none-eabi)
Main branch of a project removed atomic-polyfill crate due to it being unmaintained. The code I'm rebasing used it for fetch_add. I have to ...
3
votes
1
answer
116
views
Can (and should) a page table entry contain its own lock on RISC-V in Rust?
On RISC-V, A page table entry, which is the size of usize in Rust, has an RSW field, which is 2 bits wide. This field is supervisor defined (e.g. the kernel can use it as it pleases). Could one of ...
4
votes
0
answers
519
views
Does the *happen-before* guarantee the order of delivery for data to a file?
Consider this example:
#include <thread>
#include <atomic>
#include <stream>
int main(){
std::ofstream outFile("example.txt", std::ios::out | std::ios::trunc);
std::...
9
votes
1
answer
354
views
Memory barriers in virtual environments - do they interrupt other cores?
Let's say I call a memory barrier like:
std::atomic_thread_fence(std::memory_order_seq_cst);
From the documentation I read that this implement strong ordering among all cores, even for non atomic ...
1
vote
1
answer
258
views
Should we judge whether programs are functionally equivalent based on identical modification orders?
Consider this example:
#include <atomic>
#include <iostream>
#include <thread>
std::atomic<int> canceller = {0};
int main() {
auto t1 = std::thread([]() {
auto v = ...
3
votes
0
answers
175
views
Does the CAS operation that writes the same value theoretically have a higher probability of detecting a version change than a pure load?
Consider this example:
#include <atomic>
#include <iostream>
#include <thread>
std::atomic<int> canceller = {0};
int main() {
auto t1 = std::thread([]() {
auto v = ...
1
vote
1
answer
188
views
How to verify a possible execution is OOTA?
Consider this example:
#include <thread>
#include <atomic>
int main(){
std::atomic<int> x = 0, y = 0;
auto t1 = std::thread([&](){
if(x.load(std::memory_order::relaxed)==...
6
votes
1
answer
178
views
What is the performance effect (on x64) of __atomic_fetch_add that ignores its result?
My code is
...
fragment1 // compares several regions in D1$ to D1$/D3$
__atomic_fetch_add(&lock,-1,__ATOMIC_ACQ_REL); // stmt A
fragment2 // moves several regions from D1$/D3$ to D1$
...
5
votes
1
answer
394
views
Is it impossible that the acquire load returns `1` when the loops in other threads exit?
Consider this example:
#include <atomic>
#include <cassert>
#include <thread>
int main() {
std::atomic<int> strong = {3};
std::atomic<int> weak = {1};
auto t1 ...
2
votes
0
answers
148
views
Is it possible that the assertion can fail with memory_order::relaxed to transfer pointers?
Consider this example:
#include <iostream>
#include <atomic>
#include <thread>
#include <cassert>
int main(){
std::atomic<int> val = 1;
std::atomic<std::atomic&...