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
3
votes
0 answers

Const-ness affecting concurrent algorithms?

Are there any examples of the absence or presence of const affecting the concurrency of any C++ Standard Library algorithms or containers? If there aren't, is there any reason using the const-ness in this way is not permitted? To clarify, I'm…
3
votes
0 answers

Intel Pin multithreading instrumentation: How to only instrument the shared variable accesses between the threads?

I'm using Intel Pin to dynamically instrument the multi-threaded programs to do some data race detection. I instrument memory read/write instructions to collect memory traces at runtime and then analyze the log. The trace collection is simple, which…
2
votes
2 answers

Why does clang optimize out a loop polling a variable that another thread writes to?

While I was studying C++, I found something weird... I though that the below code would produce the result of big number(At least not 1.1). Instead the result was enter image description here Other compilers worked as expected. But the clang…
ross1573
  • 23
  • 4
2
votes
0 answers

Does Tsan instrument inline assembly?

I have some code in my project in inline assembly, does TSAN instrument it? let's look at this example: T0: x++ T1: (inline assembly code) MOV x, 2; will we get data race here(assuming no sync at all)? if so, does it instrument all assembly memory…
Moshe Levy
  • 174
  • 9
2
votes
1 answer

Why doesn't Sys.setenv() take immediate effect in R?

I'm trying to understand some behavior related to setting environmental variables within an R session. Context: on computers with multiple cores, Intel MKL can induce data races during (sufficiently large) matrix multiplies. These data races occur…
alexpghayes
  • 673
  • 5
  • 17
2
votes
1 answer

Is it a data-race when several thread *read* the same memory at the same time?

cppreference.com says: Threads and data races When an evaluation of an expression writes to a memory location and another evaluation reads or modifies the same memory location, the expressions are said to conflict. A program that has two…
Amit
  • 645
  • 1
  • 3
  • 19
2
votes
3 answers

Swift access race with os_unfair_lock_lock

I made a custom property wrapper which provides a method to access data in a mutually exclusive context using an os_unfair_lock. After testing my wrapper with TSAN enabled, an access race error was reported at the point of lock acquisition using…
2
votes
3 answers

Updating a Shared Resource in Multithreaded Program

Can someone explain the output of the following program: public class DataRace extends Thread { static ArrayList arr = new ArrayList<>(); public void run() { Random random = new Random(); int local =…
2
votes
2 answers

How to make a JavsScript callback wait for another callback?

I'm required to make two API calls simultaneously. And one of the callback has to be executed before the other. But making the calls sequential is slow and bad for user experience: axios.get("/get_some_data").then(function(resp) { …
Mary Chang
  • 865
  • 6
  • 25
2
votes
0 answers

CTPL C++ threadpooling datarace on accessing array's elements

Does accessing the same array's different elements create a data race? I have a "Matrix" wrapper class for an array with matrix interface, and i wrote a parallel multiplication by a scalar function for it. I use CTPL library for thread pools. I…
2
votes
3 answers

unsynchronized read/write of variables may cause data race?

in Java Performance Tuning by Jack Shirazi it writes: This means that access and update of variables are automatically synchronized (as long as they are not longs or doubles). If a method consists solely of a variable access or assignment, there is…
choxsword
  • 3,187
  • 18
  • 44
2
votes
1 answer

Does Non-atomic struct modification via _Atomic pointer produce data-race?

I'm trying to understand how C11 memory model works and wrote two functions containing expressions that conflict (in the sense of 5.1.2.4(p4)): struct my_struct{ uint64_t first; int64_t second; } * _Atomic instance; void* set_first(void…
Some Name
  • 8,555
  • 5
  • 27
  • 77
2
votes
0 answers

Capturing a local object in a lambda by reference can cause a data race or not?

I have some piece of code that is causing an error when it's run with Thread Sanitizer on: bool Renderer::render(std::optional cancellationToken) { const RenderWatcher renderWatcher{cancellationToken}; ... return Render(... …
Juan Herrero Diaz
  • 833
  • 1
  • 7
  • 17
2
votes
2 answers

Why does this code cause data race?

1 package main 2 3 import "time" 4 5 func main() { 6 m1 := make(map[string]int) 7 m1["hello"] = 1 8 m1["world"] = 2 9 go func() { 10 for i := 0; i < 100000000; i++ { 11 _ = m1["hello"] 12 } 13 }() 14 …
黄英俊
  • 21
  • 2
2
votes
1 answer

Is std::vector::clear()-ing an inner vector of a 2-D vector thread safe?

Let's say I have an object threadWork initialised as: vector< vector > threadWork(N_THREADS, vector()); I then deploy N_THREADS threads, each performing writes via vector::push_back()s to a separate element (its own vector
izaak_pyzaak
  • 930
  • 8
  • 23