Boost logo

Boost Users :

Subject: [Boost-users] [serialization] How to serialize an atomic<> value?
From: Merrill Cornish (merrill.cornish_at_[hidden])
Date: 2015-12-20 13:05:02


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;


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net