Questions tagged [data-race]

A data race occurs when:

  • two or more threads in a single process access the same memory location concurrently, and

  • at least one of the accesses is for writing, and

  • the threads are not using any exclusive locks to control their accesses to that memory.

When these three conditions hold, the order of accesses is non-deterministic, and the computation may give different results from run to run depending on that order. Some data-races may be benign (for example, when the memory access is used for a busy-wait), but many data-races are bugs in the program.

(source: https://docs.oracle.com/cd/E19205-01/820-0619/geojs/index.html)

108 questions
0
votes
1 answer

How to override existing symlink in Python3 if symlink already exists?

I have a working bash script which creates and/or rewrites current symbolic link to a new path without any data races. If the program tries to find a path it either gets an old path or a new path from the symlink. This works because of -f mode. Here…
pr0logas
  • 523
  • 1
  • 5
  • 14
0
votes
0 answers

Unexpected behaviour with Data race detection by Xcode Thread sanitizer

Here is a code snippet (from Aubrey Kate lesson about GCD) that will make the Xcode Thread sanitizer (A.K.A TSan) - detect a Data race: import UIKit final class MainViewController: UIViewController { var counter = 0 override func…
Hudi Ilfeld
  • 1,905
  • 2
  • 16
  • 25
0
votes
0 answers

Data race detector - OPENMP

I am new to the OPENMP game so I am currently using a race detector tool to test my skills. I wrote the following code using OPENMP sections: #include "omp.h" #include #include #define N 10000 #define Nthreads 2 int…
FATzz
  • 83
  • 5
0
votes
1 answer

C++: Does accessing different cells of the same array/vector in multiple threads create a data race?

So, I'm kinda new to parallel computing... Let's suppose I have an array arr in C++ code. Does accessing cells with different indexes from different threads create a race condition? For example if one thread will set some value let's say to arr[i]…
0
votes
1 answer

Results of doing += on a double from multiple threads

Consider the following code: void add(double& a, double b) { a += b; } which according to godbolt compiles on a Skylake to: add(double&, double): vaddsd xmm0, xmm0, QWORD PTR [rdi] vmovsd QWORD PTR [rdi], xmm0 ret If I call add(a, 1.23)…
Thomas Johnson
  • 10,776
  • 18
  • 60
  • 98
0
votes
3 answers

Is a potential data race a data race?

I am trying to understand where is the line between a data race and no date race and what are the consequences concerning undefined behavior. Consider this example: #include #include #include #include #include…
463035818_is_not_an_ai
  • 109,796
  • 11
  • 89
  • 185
0
votes
0 answers

data race problem from low-level tcl library function Tcl_NewStringObj

Since Tcl uses Apartment Threading Model as its fundamental multithreading frame, every tcl interpreter obj is bound to the thread that creates it. In my program, each thread invokes Tcl_CreateInterp to create its own interpreter the first time it…
Novak
  • 3
  • 3
0
votes
1 answer

cuda:multiple threads access the same global variable

#define dimG 16 #define dimB 64 // slovebyGPU __global__ void SloveStepGPU(float* X, float* Y, int * iCons, int* jCons, int * dCons, float* wCons, int cnt, float c) { int id = blockDim.x * blockIdx.x + threadIdx.x; for (int i = id; i
0
votes
2 answers

Trivial example of reordering memory operations

I was trying to write some code that allow me to observe reordering of memory operations. In the fallowing example I expected that on some executions of set_values() order of assigning values could change. Especialy notification = 1 may occur…
0
votes
0 answers

What matters will happen if use normal list as spsc queue?

I know it isn't thread-safe to use a normal list as spsc-queue. But I don't know why? What's wrong will happen if I do this? I read a paper about mpsc-queue, and I do some changes to the code. I change it to spsc-queue. But I don't know if my…
Rhysol
  • 481
  • 1
  • 3
  • 12
0
votes
2 answers

ThreadSanitizer detects a data race, where is the problem?

In this sample program, I'm trying to avoid using forward declaration and cyclic dependency exploiting a lambda function (called data_race) struct B{ int x; std::thread* tid; B(int _x){ x = _x; tid = NULL; } …
0
votes
0 answers

Move constructor called more times than expected

I have stepped through this code but can't understand why move constructor is called 4 times instead of one. Shouldn't it be called only once? I have stepped through the code using CLion on Mac. Here is the outcome on the console: Vehicle #0 Default…
0
votes
0 answers

Altering a value in map inside the iteration of the same map(Nested iterator) C++

I am facing some strange issue in the code below which is compiled in linux, The below piece of code iterates a map "ObjectsMap" from Begin and inside the iteration loop, I am trying to change the value of a different key in the same map…
Sel_va
  • 588
  • 5
  • 25
0
votes
2 answers

What guarantees that different unrelated objects in two unrelated threads don't have an (unavoidable) race condition?

When different threads only use unrelated objects and literally do not share anything they cannot have a race condition, right? Obviously. Actually all threads share something: the address space. There is no guarantee that a memory location that was…
curiousguy
  • 8,038
  • 2
  • 40
  • 58
0
votes
1 answer

Why is this Java program containing two volatile writes data race free?

Consider the following Java program: static volatile int shared; public static void main(final String[] args) { final Runnable r = () -> { shared = 1; }; new Thread(r).start(); new Thread(r).start(); } Because shared is marked…
cic
  • 7,310
  • 3
  • 23
  • 35