是否有可能获取atomic_int的基础存储的地址? [英] Is it possible to get the address of the underlying storage for an atomic_int?

查看:84
本文介绍了是否有可能获取atomic_int的基础存储的地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 std::atomic_int futex linux函数.

I want to use an std::atomic_int with the futex linux function.

但是,futex函数需要一个地址位置,我不确定仅使用atomic_int对象的地址是否正确.

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.

因此,我想知道是否有可能获取atomic_int的基础存储的地址,然后将其传递给futex调用.

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.

推荐答案

也许不是.

手动

int futex(int *uaddr, int op, int val, const struct timespec *timeout,
    int *uaddr2, int val3);

The uaddr argument needs to point to an aligned integer which stores the counter.  The operation to execute  is  passed via the op argument, along with a value val.

您的atomic_int应该对齐.

在gcc 4.7.2(在Fedora 18上)中,文件:/usr/include/c++/4.7.2/bits/atomic_base.h

In gcc 4.7.2 (which on Fedora 18), file: /usr/include/c++/4.7.2/bits/atomic_base.h

// Base types for atomics.
template<typename _IntTp>
  struct __atomic_base;
...
/// atomic_int
typedef __atomic_base<int>                    atomic_int;
...
template<typename _ITp>
struct __atomic_base
{
private:
  typedef _ITp      __int_type;

  __int_type        _M_i;

// some operations
...

atomic_int只是数据__int_type _M_i;的包装,其中__int_type是您传入的模板参数.因此,它是一个整数.并且不能保证该结构在跨平台中对齐.

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.

这篇关于是否有可能获取atomic_int的基础存储的地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆