protect two variables with atomic in a multi-threading environement
//Thread 1std::uint64_t getAndResetProcessingTimeInMicro(){ auto value = m_cumulatedProcessingTimeCount.load(boost::memory_order_acquire); if (value == 0) return 0; auto processingTime =...
View ArticleAnswer by Sorin for protect two variables with atomic in a multi-threading...
If you want to do two different atomic operations together you need a mutex both when you write and when you read them. Mutexes don't prevent context switches, but used this way guarantee that you...
View ArticleAnswer by johnnycrash for protect two variables with atomic in a...
make a union like this:union CData { struct { __int32 a; __int16 c; __int16 d:2, e:14; // you get the idea... } __int64 n64;}Use all the variables using the struct members, do the atomic stuff with n64.
View ArticleAnswer by David Schwartz for protect two variables with atomic in a...
You can, but you probably don't want to.You need an atomic shared_ptr to the struct that holds both variables. The process for reading is just to copy the shared_ptr atomically and look at the struct...
View Article