Question on race condition | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

Question on race condition

Hi I have a function and it has a local variable..... As thread have their own stack frame, we dont have data race condition for local variables.... Is this true ? Also data race happens when we have global variable and both the thread writes or one reads and one writes..... in these two conditions, data race may occur.... if both the threads only reads data from global variable, data race does not happen... Is above all details correct ?

28th Jul 2022, 4:36 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
1 Resposta
+ 1
True, having all local variables prevents data race condition, as long as none of the local variables are static. Use only dynamic local variables. True, a data race only occurs when you have writable shared state space.
29th Jul 2022, 12:02 AM
Brian
Brian - avatar