为什么编译器说'pthread_getthreadid_np'没有在这个范围内声明? [英] why compiler says ‘pthread_getthreadid_np’ was not declared in this scope?

查看:1477
本文介绍了为什么编译器说'pthread_getthreadid_np'没有在这个范围内声明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Debian稳定。我在C ++中编写一个多线程应用程序,并使用 g ++ 编译器和 -lpthread参数进行编译。

I am using Debian stable. I was coding a multithreaded application in C++ and using g++ compiler and -lpthread argument to compile.

但是函数 pthread_getthreadid_np()无效:


错误:'pthread_getthreadid_np'未在此范围内声明

error: ‘pthread_getthreadid_np’ was not declared in this scope

是什么原因导致此错误? $ b

what is causing this error?

推荐答案

_np 表示不可移植(或不是Posix),在所有平台上。这个函数似乎是特定于BSD,为调用线程获得平台特定的整数ID。它不存在于Linux上。

_np means "not portable" (or "not Posix"), meaning it's not available on all platforms. This function seems to be specific to BSD, to get a platform-specific integer ID for the calling thread. It doesn't exist on Linux.

根据使用的不同,您可能也可能不能使用 pthread_t pthread_self 函数(在Linux上是一个整数类型)返回的c $ c>句柄,或由特定于Linux的 gettid 系统调用。或者,重新思考你在做什么,所以你不需要处理线程标识。

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. Alternatively, rethink whatever you're doing so you don't need to deal with thread identities.

这篇关于为什么编译器说'pthread_getthreadid_np'没有在这个范围内声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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