简体   繁体   English

从std :: thread到相关的pthread

[英]Going from an std::thread to the related pthread

In Linux, I need to check if an address belongs to the stack of the thread or not. 在Linux中,我需要检查一个地址是否属于该线程的堆栈。 I have found that pthread_attr_getstack works for the purpose. 我发现pthread_attr_getstack可以用于此目的。

I presume that std::thread is based on pthreads, and so from my std::thread I may find a pthread and use it along with pthread_attr_getstack in order to check if the pointer points inside the stack. 我假设std :: thread基于pthreads,所以从我的std :: thread我可以找到一个pthread并与pthread_attr_getstack一起使用以检查指针是否指向堆栈内部。 Is that possible? 那可能吗? How? 怎么样?

Did you try reading the documentation? 你试过阅读文档了吗? It has it very clear: 它非常清楚:

std::thread::native_handle: Returns the implementation defined underlying thread handle. std :: thread :: native_handle:返回实现定义的底层线程句柄。

See more here: http://en.cppreference.com/w/cpp/thread/thread/native_handle 在此处查看更多信息: http//en.cppreference.com/w/cpp/thread/thread/native_handle

Having obtained native_handle (and reasonably believing your implementation is based on pthreads, as it might not be!) you can pass this handle to any pthread routines your heart desires. 获得native_handle (并且合理地相信你的实现是基于pthreads,因为它可能不是!)你可以将这个句柄传递给你心中想要的任何pthread例程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM