简体   繁体   中英

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 ).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM