|
Boost Users : |
Subject: Re: [Boost-users] Using boost atomics on data residing in shared memory
From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2012-04-04 13:56:33
El 03/04/2012 11:35, Philip Windle escribió:
> 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<shared_memory_object> shm_obj;
>
> boost::shared_ptr<mapped_region> 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<volatile
> boost::uint32_t*>(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
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