c++ - Qt Threading synchronization -
consider the following situation:
i have qthread modifies variable (let's call counter
) , qtimer periodically reads counter
. know have synchronize variables might modified multiple threads @ same time - need synchronization in case well, when there 1 thread reading , 1 thread writing variable?
yes, need synchronisation — if no other reason standard says program has undefined behaviour if there data race.
you can either synchronize mutex guards counter variable, suppose "traditional" way, or can use std::atomic<int>
variable counter, can access without creating data race.
Comments
Post a Comment