I want to use an std::atomic_int
with the futex
linux function.
However, the futex
function requires an address location, and I am uncertain about the correctness of just using the address of the atomic_int
object.
Therefore, I wonder if it is possible to get the address of the underlying storage for an atomic_int
, so I can then pass it to the futex
call.
Maybe not.
In manual
Your
atomic_int
should be aligned.In gcc 4.7.2 (which on Fedora 18), file:
/usr/include/c++/4.7.2/bits/atomic_base.h
atomic_int
is just a wrapper of data__int_type _M_i;
where__int_type
is the template parameter you pass in. So it's an integer. And the struct is not guaranteed aligned in cross platform.Portably, no. Realistically, an
atomic_int
is probably justsizeof(int)
bytes of memory like a regularint
on any modern C++ implementation. Ifsizeof(std::atomic<int>) == sizeof(int)
, go for broke and just pass its address tofutex
and see what happens.