Data race in thread | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 2

Data race in thread

Data race in threading Hi I have a vector of structor.. this structure objects are created dynamically and pushed to vector.. I am planning this in main thread Once a entry is appended to vector of structure objects, one additional thread from a thread pool is assigned a task which need to read data from vector of structure objects. As it is reading of data from vector for a thread pool threads, i just dont need to use mutex or semaphore... Correct ?? I understand that vector might allocate data again and again at new location when capacity reaches size for any push operation. This might cause the data race and hence I am setting capacity as well in advance with reserving space for 2 million data... i am sure my implementation is never gonna push more than these many objects... With this , do i need to take care of anything else to avoid data race ? Thanks for your suggestions well in advance... feel free to share different view and dont hesitate to ask for any query in case you have some

28th Oct 2022, 1:09 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
1 Réponse
+ 3
Yep, sounds fine to me. If the existing vector data is not being changed or deleted by any threads, and data is only added to the end of the vector, then on the surface I see no concern for race condition.
28th Oct 2022, 11:21 PM
Brian - avatar