C++/Boost: Synchronize access to a resource across multiple method (getter) calls
I'm not sure if this is a question regarding programming technique or design but I'm open for suggestions.

The problem: I want to create an abstraction layer between data sources and consumers. The idea is that the consumers only "know" the interfaces (abstract base class) of different source types. Each of this source types usually consists of several individual values which all have their own getter methods (e.g. getValue1(), getValue2() etc.). 

    class IDataSource {
        
        public:
            virtual int getValue1() = 0;
            virtual int getValue2() = 0;

    };

Since updates to the data sources are done by a different thread (details are up to the implementation of the interface), synchronizing getters and also the update methods seems like a reasonable approach to ensure consistency.

So far so good. In most cases this level of synchronization should suffice. However, sometimes it might be necessary to aquire more than value (with consecutive getValueX() calls) and ensure that no update is happening in between. Whether this is necessary or not (and which values are important) is up to the consumer.

Now I was wondering, what would be a proper way to do this. 

Solutions I could think of:

- Group all possible values into a struct (or class) and add an additional (synchronized) getter returning copies of all values at once - seems like a lot of unnecessary overhead to me in case only 2 or 3 out of maybe 10 values are needed.

- Add a method returning a reference to the mutex used within the data source to allow locking by the consumer - this doesn't feel like "good design". And since getters are already synchronized, using a recursive mutex is mandatory. However, I assume that there are multiple readers but only one writer and thus I'd rather go with a shared mutex here.

Thanks for your help.
C++/Boost: Synchronize access to a resource across multiple method (getter) calls
===

I'm not sure if this is a question regarding programming technique or design but I'm open for suggestions.

The problem: I want to create an abstraction layer between data sources and consumers. The idea is that the consumers only "know" the interfaces (abstract base class) of different source types. Each of this source types usually consists of several individual values which all have their own getter methods (e.g. getValue1(), getValue2() etc.). 

    class IDataSource {
        
        public:
            virtual int getValue1() = 0;
            virtual int getValue2() = 0;

    };

Since updates to the data sources are done by a different thread (details are up to the implementation of the interface), synchronizing getters and also the update methods seems like a reasonable approach to ensure consistency.

So far so good. In most cases this level of synchronization should suffice. However, sometimes it might be necessary to aquire more than value (with consecutive getValueX() calls) and ensure that no update is happening in between. Whether this is necessary or not (and which values are important) is up to the consumer.

Now I was wondering, what would be a proper way to do this. 

Solutions I could think of:

- Group all possible values into a struct (or class) and add an additional (synchronized) getter returning copies of all values at once - seems like a lot of unnecessary overhead to me in case only 2 or 3 out of maybe 10 values are needed.

- Add a method returning a reference to the mutex used within the data source to allow locking by the consumer - this doesn't feel like "good design". And since getters are already synchronized, using a recursive mutex is mandatory. However, I assume that there are multiple readers but only one writer and thus I'd rather go with a shared mutex here.

Thanks for your help.