# Benign data races?

**URL:** <https://discourse.julialang.org/t/benign-data-races/92424>\
**Category:** Performance\
**Tags:** multithreading\
**Created:** [January 2, 2023, 6:15pm UTC](https://discourse.julialang.org/t/benign-data-races/92424 "2023-01-02T18:15:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pitsianis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pitsianis/32/26588_2.png) [@pitsianis](https://discourse.julialang.org/u/pitsianis)\
**Post date:** [January 2, 2023, 6:15pm UTC](https://discourse.julialang.org/t/benign-data-races/92424/1 "2023-01-02T18:15:00Z")

</div>

Somebody, please elaborate on the dangers alluded to by the manual in section [“Data-race freedom”](https://docs.julialang.org/en/v1.8/manual/multi-threading/#Data-race-freedom-1)

> Julia is not memory safe in the presence of a data race. Be very careful about reading _any_ data if another thread might write to it!

There are parallel algorithms that are not affected by a data race where one thread is updating a value in an array, and many threads are reading it. If some readers miss the fresh value and instead read the stale one, they will read a newer value at the next iteration. On the contrary, fewer synchronizations might be needed without affecting convergence (increasing the number of iterations) too dramatically.

---

<div class="post-metadata">

**Author:** ![jameson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jameson/32/23_2.png) [@jameson](https://discourse.julialang.org/u/jameson)\
**Post date:** [January 3, 2023, 4:11am UTC](https://discourse.julialang.org/t/benign-data-races/92424/2 "2023-01-03T04:11:27Z")

</div>

That is known as a benign data race, and they have shown by the authors of C/C++/Java to lead to program mis-executions. Don’t do it. Use atomics, as the standards authors intended.

> **[Benign Data Races Considered Harmful](https://bartoszmilewski.com/2020/08/11/benign-data-races-considered-harmful/)**
>
> The series of posts about so called benign data races stirred a lot of controversy and led to numerous discussions at the startup I was working at called Corensic. Two bastions formed, one claiming…

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [January 10, 2023, 5:52pm UTC](https://discourse.julialang.org/t/benign-data-races/92424/3 "2023-01-10T17:52:59Z")

</div>

The manual isn’t saying that data races are logically wrong, it’s saying that Julia, as is the prevailing trend among programming languages, chooses to make data races illegal, which is done to enable more performant implementation AFAIK. I guess the optimizer has a much easier job if it can assume no races exist.
