简体   繁体   English

为什么编译器说'pthread_getthreadid_np'没有在这个范围内声明?

[英]why compiler says ‘pthread_getthreadid_np’ was not declared in this scope?

I am using Debian stable. 我正在使用Debian稳定。 I was coding a multithreaded application in C++ and using g++ compiler and -lpthread argument to compile. 我用C ++编写了一个多线程应用程序,并使用g++编译器和-lpthread argument进行编译。

But the function pthread_getthreadid_np() not works: 但函数pthread_getthreadid_np()不起作用:

error: 'pthread_getthreadid_np' was not declared in this scope 错误:未在此范围内声明'pthread_getthreadid_np'

what is causing this error? 是什么导致了这个错误?

_np means "not portable" (or "not Posix"), meaning it's not available on all platforms. _np表示“不可移植”(或“不是Posix”),这意味着它并非在所有平台上都可用。 This function seems to be specific to BSD, to get a platform-specific integer ID for the calling thread. 此函数似乎特定于BSD,以获取调用线程的特定于平台的整数ID。 It doesn't exist on Linux. 它在Linux上不存在。

Depending on what it's used for, you may or may not be able to use the pthread_t handle returned by the portable pthread_self function (which is an integer type on Linux), or the numeric thread ID returned by the Linux-specific gettid system call. 根据它的用途,您可能会也可能无法使用便携式pthread_self函数(Linux上的整数类型)返回的pthread_t句柄,或者特定于Linux的gettid系统调用返回的数字线程ID。 Alternatively, rethink whatever you're doing so you don't need to deal with thread identities. 或者,重新考虑你正在做的事情,这样你就不需要处理线程身份。

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

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