Roman Blahuta
Roman Blahuta

Reputation: 29

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] and the second one will write into arr[j] ( where i != j ).

Upvotes: 0

Views: 714

Answers (1)

mentallurg
mentallurg

Reputation: 5207

If you make sure that all threads use the same array instance and that every thread uses its own index, then there will be no race.

Upvotes: 1

Related Questions