C ++ 11'native_handle'不是'std :: this_thread'的成员 [英] C++11 'native_handle' is not a member of 'std::this_thread'

查看:78
本文介绍了C ++ 11'native_handle'不是'std :: this_thread'的成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下代码段中,

void foo() {
  std::this_thread::native_handle().... //error here
}

int main() {
  std::thread t1(foo);

  t1.join();
  return 0;
}

您如何获得 native_handle 来自 std :: this_thread 来自函数 foo 内?

How do you get the native_handle from std::this_thread from within the function foo?

推荐答案

线程无法自动获得对其自己的 std :: thread 的访问权。这是有意的,因为 std :: thread 是仅移动类型。

There is no way for a thread to autonomously gain access to its own std::thread. This is on purpose since std::thread is a move-only type.

我相信您是请求是 std :: thread :: id native_handle()成员,这是一个有趣的建议。据我所知,目前尚不可能。可以这样使用:

I believe what you're requesting is a native_handle() member of std::thread::id, and that is an interesting suggestion. As far as I know it is not currently possible. It would be used like:

void foo()
{
    auto native_me = std::this_thread::get_id().native_handle();
    // ...
}

工作,甚至存在。但是我想大多数POSIX平台都可以支持它。

It wouldn't be guaranteed to work, or even exist. However I imagine most POSIX platforms could support it.

尝试更改C ++标准的一种方法是提交问题。 此处是如何操作的说明。

One way to try to change the C++ standard is to submit issues. Here are directions on how to do so.

这篇关于C ++ 11'native_handle'不是'std :: this_thread'的成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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