Efficent way of synchronizing between data I'm currently working on a project where I have a punch of raw data and multiple components that use that data for various tasks. I would like to separate the raw data from the components as much as possible and keep the raw data as only data (So no logic or functionality) but the components should be able to read and write to the raw data at any time.

The program will run each component and once all components have been run than the process repeats until the program shuts down. A component can be threaded, but it must join before the process repeats.

Each component will create objects based on the data that will do various things. To avoid having to create and delete those objects at each run for performance the objects must persist and synchronize it's data with the raw data at the beginning of the run.

So to summarize, the design should look something like this


This brings up the issue of synchronization as I need the component to synchronize its data with the raw data at beginning of each run.

Speed is some what important and so I can't go through each object and check if it it's members are equal to that of the component as that is process consuming especially considering the data will not change for the majority of the time.

What I thought about doing is give each object a GUID and every time one of it's values changes than I generate a new GUID. Therefore, if the GUID in the component is different than what it is in the raw data than the value must have changed.

This is simple to implement with getter and setter for each member and in the setter I just generate a new GUID.

Now, I wanted to avoid using getter and setter for two reasons. First, that increases the amount of typing I have to do and that will only increase my chance of getting arthritis sooner. Second, I'm scared my colleagues will take the lazy way and not add getter and setter for when they add members or passing the setter all together and setting the value directly causing a huge headache and waste of debugging time.

Therefore, I decided to create a template class that handles this for me.

This is what I came up with

#include&lt;iostream&gt;
#include "uuid.hpp"
#include "uuid_generators.hpp"
#include "uuid_io.hpp"

template&lt;typename T&gt;
class MemberTracker
{
private:
    T m_value;
    boost::uuids::uuid&amp; m_KeepingTrackOf;
public:
    MemberTracker(boost::uuids::uuid&amp; KeepTrackof)
        : m_KeepingTrackOf(KeepTrackof)
    {
    }
    operator T()
    {
        return m_value;
    }
    MemberTracker&amp; operator=(T input)
    {
        this-&gt;m_KeepingTrackOf = boost::uuids::random_generator()();
        this-&gt;m_value = input;
        return *this;
    }
};

class ObjectRawData
{
public:
    boost::uuids::uuid guid;
    MemberTracker&lt;int&gt; value;
    ObjectRawData()
        : value(guid)
    {
        guid = boost::uuids::random_generator()();
    }
    ObjectRawData(const ObjectRawData &amp;obj)
        : value(guid)
    {
    }
};

int main()
{
    ObjectRawData h;
    std::cout &lt;&lt; h.guid &lt;&lt; std::endl;
    h.value = 4;    
    std::cout &lt;&lt; h.guid &lt;&lt; std::endl;
}


The only thing I don't like about this design is that I have to pass in the GUID as a parameter in the constructor.

So, my question is did I go in the right direction and what are the flaws of this design??
I think you have two main choices, have the components throw events when they dirty the data. 

The plus here is that events are extremely multithreaded friendly.
the minus is the program might have to know about how to sync the dirty data.

The other option is to have an abstract class with two methods doWork() and sync(). 
First run a parallel call to all the components.dowork
The when all completed run down each components.sync()

This has the plus of the program not knowing about data sync but the component stores its own dirty list and is very customizable as a result..
This has the minus of the components knowing about data sync.