Is atomicity guaranteed on data residing in shared memory?
E.g. Processes allocate shared memory as follows using either
create_only and truncate or open_only:
#defineSHARED_MEM_SIZE sizeof(boost::uint32_t)
#defineSHARED_MEM_NAME "SHMTest"
boost::shared_ptr shm_obj;
boost::shared_ptr mapping;
std::string sharedMemoryName(SHARED_MEM_NAME);
shm_obj.reset(new shared_memory_object(create_only,
sharedMemoryName.c_str(), read_write));
shm_obj->truncate(SHARED_MEM_SIZE);
mapping.reset(new mapped_region(*shm_obj, read_write, 0, SHARED_MEM_SIZE));
Then, they use the boost atomic functions to read and write to the memory:
volatileboost::uint32_t* temp = static_cast(mapping->get_address());
unsignedint value = boost::interprocess::detail::atomic_read32(temp);
boost::interprocess::detail::atomic_write32(temp, value);
Are these memory accesses guaranteed to be atomic? Platform is Linux if
that makes a difference.
Yes, but those functions are implementations details that make change.
what we really need is to have boost.atomic guaranteed to work in shared
memory.
Ion