[serialization] How to serialize an atomic<> value?
I am running Boost_1_60_0 on Windows 10 64bit on MinGW64: I have this class data member I want to serialize: std::atomic< std::time_t > mUpdate; Since I'm on a 64-bit machine, serialization recognizes that as atomic< long long int >. However, given ar & mUpdate; serialization says it does not know how to serialize atomic< long long int >. My solution, which compiles cleanly, is std::time_t updateTime = mUpdateTime.load(); ar & updateTime; mUpdateTime = updateTime; // assign is atomic My reasoning is that on load (ar => mUpdateTime), the first line is useless, but harmless. Similarly, on save (ar <= mUpdateTime), the last line is redundant, but also harmless. Of course, the application is not executing during serialization and de-serialization. As I said, this compiles without error or warning; but I worry that I have missed something. Any thoughts? Merrill Cornish Once I see how to get the above working, my next project will be std::atomic< std::shared_ptr< boost::variant<...> > mValue;
On 12/20/15 10:05 AM, Merrill Cornish wrote:
I am running Boost_1_60_0 on Windows 10 64bit on MinGW64:
I have this class data member I want to serialize:
std::atomic< std::time_t > mUpdate;
Since I'm on a 64-bit machine, serialization recognizes that as atomic< long long int >. However, given
ar & mUpdate;
serialization says it does not know how to serialize atomic< long long int >. My solution, which compiles cleanly, is
std::time_t updateTime = mUpdateTime.load(); ar & updateTime; mUpdateTime = updateTime; // assign is atomic
My reasoning is that on load (ar => mUpdateTime), the first line is useless, but harmless. Similarly, on save (ar <= mUpdateTime), the last line is redundant, but also harmless. Of course, the application is not executing during serialization and de-serialization.
As I said, this compiles without error or warning; but I worry that I have missed something.
Any thoughts?
You have missed something. You can easily make small serialization
implementations for any serializable type. You do it just as you would
for you own type. look in the manual under non-intrusive serialization.
Look for examples in the library.
given that it looks like std::time_t already has serialzation support,
you'll have to do it for atomic<T>. This will look something like:
template
participants (2)
-
Merrill Cornish
-
Robert Ramey