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

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -