Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Global arrays in threads

I know you have to synchronize your threads to be able to change your global variables content safely in a multithreaded application (where multiple threads are trying to change the variable data at the same time). But is this also necessary if you use a global array, where each thread only uses one of the n elements?

Thanks in advance!

like image 430
Jori Avatar asked Sep 06 '25 06:09

Jori


1 Answers

If each thread only uses one element, and the array's location in memory is never changed, then it's absolutely safe without synchronization.

like image 174
Ry- Avatar answered Sep 09 '25 02:09

Ry-