[Interprocess] uint64 atomic
Hi, I am new to boost-interprocess. I am trying to store some of my data structures in shared memory using boost::interprocess. Each of my data structure(s) contain a bunch of counters (basically size_t values) updated atomically. In the traditional world, std::atomic supports atomic update for size_t. However, I came to know that boost::interprocess doesn't support atomic update for uint64. I've looked at pairing my counter with a lock for synchronization purposes. I've implemented it and it seems to work. However, the upgradable_mutex is consuming 144bytes while my counter is 8bytes(size_t) making it cost prohibitive. Alternatively, I could use one lock for all the counters of a class to spread the cost but that'd affect the performance and affect parallelism. I'd appreciate it if someone could offer any alternate suggestions. Thanks. Dk. -- View this message in context: http://boost.2283326.n4.nabble.com/Interprocess-uint64-atomic-tp4695000.html Sent from the Boost - Users mailing list archive at Nabble.com.
On 30/05/2017 23:47, dnj0496 via Boost-users wrote:
Hi, I am new to boost-interprocess. I am trying to store some of my data structures in shared memory using boost::interprocess. Each of my data structure(s) contain a bunch of counters (basically size_t values) updated atomically. In the traditional world, std::atomic supports atomic update for size_t. However, I came to know that boost::interprocess doesn't support atomic update for uint64.
I've looked at pairing my counter with a lock for synchronization purposes. I've implemented it and it seems to work. However, the upgradable_mutex is consuming 144bytes while my counter is 8bytes(size_t) making it cost prohibitive. Alternatively, I could use one lock for all the counters of a class to spread the cost but that'd affect the performance and affect parallelism.
You can try Boost.Atomic. It should work on platforms where you know you have 64 bit atomic instructions. In general Interprocess should migrate to Boost.Atomic, which should be faster. Ion
Thanks Ion, Does it mean any size_t value stored in shared memory will be updated atomically if I use boost.atomic? What is the difference between Boost.Atomic vs std::atomic? Can std::atomic work with boost::interprocess? When do you foresee boost.interprocess moving to boost.atomic? Thanks
On May 31, 2017, at 8:35 AM, Ion Gaztañaga via Boost-users
wrote: On 30/05/2017 23:47, dnj0496 via Boost-users wrote: Hi, I am new to boost-interprocess. I am trying to store some of my data structures in shared memory using boost::interprocess. Each of my data structure(s) contain a bunch of counters (basically size_t values) updated atomically. In the traditional world, std::atomic supports atomic update for size_t. However, I came to know that boost::interprocess doesn't support atomic update for uint64. I've looked at pairing my counter with a lock for synchronization purposes. I've implemented it and it seems to work. However, the upgradable_mutex is consuming 144bytes while my counter is 8bytes(size_t) making it cost prohibitive. Alternatively, I could use one lock for all the counters of a class to spread the cost but that'd affect the performance and affect parallelism.
You can try Boost.Atomic. It should work on platforms where you know you have 64 bit atomic instructions. In general Interprocess should migrate to Boost.Atomic, which should be faster.
Ion _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org https://lists.boost.org/mailman/listinfo.cgi/boost-users
On 31/05/2017 20:33, Dk Jack via Boost-users wrote:
Thanks Ion, Does it mean any size_t value stored in shared memory will be updated atomically if I use boost.atomic?
Yes.
What is the difference between Boost.Atomic vs std::atomic?
Boost.Atomic is an implementation of the standard atomic operations that work in compilers without atomic support and older versions of the standard. Both should behave similarly and should be interoperable when "is_lock_free()" is true for both std::atomicstd::size-t and boost::atomicstd::size_t
Can std::atomic work with boost::interprocess?
Yes, it should. When do you foresee boost.interprocess
moving to boost.atomic? Thanks
I don't know, it's in my low-priority list since users can use Boost.Atomic or std::atomic and Interprocess' atomic operations are an implementation detail that users should not use. Ion
participants (3)
-
Dk Jack
-
dnj0496
-
Ion Gaztañaga