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

Confusion about definition of data race

A data race happens when there are two memory accesses in a program where both: target the same location are performed concurrently by two threads are not reads are not synchronization operations This definition is taken from, which borrows it…
user3834119
  • 411
  • 9
  • 21
0
votes
3 answers

std::mutex usage example

I have written this piece of code as test: #include #include #include int counter = 0; auto inc(int a) { for (int k = 0; k < a; ++k) ++counter; } int main() { auto a = std::thread{ inc, 100000 }; …
Emma Rossignoli
  • 935
  • 7
  • 25
0
votes
1 answer

Is it possible to to start a thread in C# with its own variables which are not updated by subsequent calls?

I've created a class with a method which is called by different threads (outside the class). Before calling the method, the threads update their own set of parameters by updating a dictionary of properties in the class. I parameterise the method by…
0
votes
2 answers

Handling multiple data races with slack bot

I'm working on a slack bot as my first golang project and while the functionality of this specific bot command works great, it can randomly panic and throw an error. I was able to determine that I have data races going on, specifically with my two…
Blooze
  • 1,987
  • 4
  • 16
  • 19
0
votes
1 answer

Avoid data race worker with golang

I have a jobWorker which should deal with jobs and in this worker had database read write, log file, receive api and some data computing. var mystruct strcut{} func worker(v) { Get data from database ... Update database status ... …
Weiwei
  • 17
  • 3
0
votes
0 answers

Single write - single read big memory buffer sharing without locks

Let's suppose I have a big memory buffer used as a framebuffer, what is constantly written by a thread (or even multiple threads, guaranteed that no two threads write the same byte concurrently). These writes are indeterministic in time, scattered…
Ferenc
  • 779
  • 1
  • 6
  • 14
-1
votes
1 answer

Redigo concurrent Set gives data race

I'm running this test against my redigo functions to see if it supports massive concurrent writes, here're the code import ( "github.com/gomodule/redigo/redis" "log" "os" ) // Redis connection pool var RedisPool *redis.Pool func…
dulan
  • 1,584
  • 6
  • 22
  • 50
-1
votes
1 answer

May the go compiler reorder following code?

Lately, I found some code looks like this: var m map[int]int func writem() { tmpm := make(map[int]int) for i := 0; i < 4000000; i++ { tmpm[i] = i + 10 } m = tmpm } func readm() { for k, v := range m { _, _ = k,…
lty
  • 108
  • 1
  • 6
-1
votes
1 answer

Is copy concurrency safe in golang?

In some circumstance, i would copy some content to different piece of the slice. Like this a := make([]int, 10) for i := 0; i < 10; i++ { b := []int{i} go func(i int) { copy(a[i:i+1], b) …
HolaYang
  • 419
  • 2
  • 10
-2
votes
1 answer

Is passing value by reference thread-safe?

I have a following code: #include void foo(int& value) { // do nothing } int main() { int value = 42; std::thread t1([&value]{ foo(value); }); std::thread t2([&value]{ value = 100500; }); t1.join(); t2.join(); return…
mouse_00
  • 593
  • 3
  • 13
-2
votes
1 answer

Data races resolution C++

I wanted to ask for some help in solving the data races in my program. I started with a simulation of how things should work if I were using multithreading and then modified the code so that I can check if I really obtain those results but I don't…
LordGrim
  • 13
  • 4
-2
votes
1 answer

Why am I getting deadlock and how to fix it (synch)?

Getting deadlock somewhere. What is causing it and how should it be fixed? Trying to create a molecule creation. Function Make takes input as a string: func testMolecule() { water := New() water.Make("HOH") // water.Make("OOHHHH") …
-2
votes
2 answers

Unexpected behavior from launching a method call on a loop variable as a goroutine

I read this article and decided to repeat such behavior myself and experiment with that: package main import ( "fmt" "time" ) type User struct { i int token string } func NewUser(i int, token string) User { user :=…
Wynell
  • 39
  • 6
-2
votes
1 answer

Data race issues while reading data from file and sending it simultaneously

I am trying to read data from a file and send it immediately the chunk read without waiting the other goroutine to complete file read. I have two function func ReadFile(stream chan []byte, stop chan bool) { file.Lock() defer file.Unlock() …
sendan
  • 18
  • 4
-2
votes
1 answer

Wanted data-race or bad design?

I am implementing an app that integrates a third party API that has a limit of hits per second. I wrote my adapter and I was a happy man until I run my tests with the race condition detector. The design is simple, there is a: A struct that counts…
LeniM
  • 21
  • 5