Are atoms or mutexes mandatory for mapping tasks in multi-threaded applications?

I am using C ++ 11 and the built-in streaming class std::thread. Using std::atomicor std::mutexsimplifies data synchronization, but I wonder if this is really necessary for "insensitive" tasks - while saving the application without errors. Let them say that the class is kind of

class FPS
{
  private:
    int rate;
  public:
    void change(const int i)
    {rate = i;}
    int read(void)
    {return rate;}
};

saving the frame rate of the camera. The application has one stream for data collection (frame capture, etc.), which reads the frame rate, and the other stream processes a graphical interface that displays the frame rate. In this case, the display is “not critical,” which means that in some cases the display may delay the actual speed. I can, of course, just use atomic to make it safe, but still I wonder if this should really guarantee error-free program performance, assuming the application runs on a multi-core processor.

+4
source share
1 answer

++ , . ++ , ++.

, , , ++ .

, int, , . , int int .

, , - , . , , , , : undefined.

, . - , , , : , , .

, .

http://en.cppreference.com/w/cpp/atomic/memory_order , , atomics. , -, , . , , , , , .

"- " , (, , ).

+8

All Articles