mercredi 6 novembre 2019

Is it safe to update object in thread without locks if other threads will not take access to it?

I have a vector of entities. At update cycle I iterate through vector and update each entity: read it's position, calculate current speed, write updated position. Also, during updating process I can change some other objects in other part of program, but each that object related only to current entity and other entities will not touch that object.

So, I want to run this code in threads. I separate vector into few chunks and update each chunk in different threads. As I see, threads are fully independent. Each thread on each iteration works with independent memory regions and doesn't affect other threads work.

Do I need any locks here? I assume, that everything should work without any mutexes, etc. Am I right?

Aucun commentaire:

Enregistrer un commentaire