4,053 questions
0
votes
0
answers
134
views
Is it true that only a single thread can guarantee the linearizability?
Consider this example:
#include <atomic>
#include <chrono>
#include <thread>
int main() {
std::atomic<long int> key;
auto t1 = std::thread([&]() {
auto now =...
1
vote
0
answers
184
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::...
-1
votes
0
answers
135
views
Is the updated data in MySQL guaranteed to be visible to the query in another thread when the notification doesn't establish synchronization?
Consider this example:
#include <thread>
#include <atomic>
extern char* mysql_query(MYSQL* mysql,char const*);
extern char* do_mysql_update(MYSQL* mysql);
int main(){
std::atomic<bool&...
7
votes
1
answer
271
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
253
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
168
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
175
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
164
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
389
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
144
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&...
0
votes
2
answers
152
views
compare_exchange_strong failed to update the expected value
I am trying to implement a lock-free multiple-producer-single-consumer ring buffer in C++. Here is the full definition and the test code.
#include <iostream>
#include <memory>
#include <...
3
votes
1
answer
160
views
Do methods on the ECMAScript Atomics object enforce that all prior shared memory operations are completed first?
The ECMAScript Language Specification states:
Atomics are carved in stone: Program transformations must not cause any Shared Data Block events whose [[Order]] is seq-cst to be removed from the is-...
1
vote
2
answers
217
views
Does this execution violate the observable behavior if ignoring the OOTA?
Consider this example:
#include <iostream>
#include <thread>
#include <atomic>
int main(){
std::atomic<int> val = 0;
std::atomic<bool> flag = false;
auto t1 = std::...
1
vote
1
answer
201
views
How to benchmark atomic<int> vs atomic<size_t>?
I have a bounded queue with small size that definitely fit in int. So I want to use atomic<int> instead of atomic<size_t> for indexing/counter, since int is smaller it should be faster.
...
0
votes
0
answers
353
views
Can external IO operations be considered as if seq_cst operations in the reasoning of multithreaded programs?
Consider this example:
// thread A:
start_transaction();
update_mysql();
commit_transaction(); // remove "key" from mysql tables
remove_redis_cache("key");
// thread B:
std::...