这是pthread C++程序的不可移植错误吗
Is this a non portable error of a pthread C++ program
我正在为pthread C++程序编码。
我出错了:"pthread_getunique_np"未在此范围中声明
pthread_getunique_np或其他带有"*np"的内容是不可移植的。
我无法从网上帖子中找到解决方案。
我知道_np意味着它不是POSIX标准。
如何绕过这个?我需要包括一些头文件或其他替代文件?
感谢
正如Martin所说,在许多系统上,您可以只使用线程的pthread_t
作为唯一标识符。您可以使用pthread_self(3)
(即POSIX)来检索它。您可以使用函数pthread_equal(3)
来测试两个pthread_t
的等效性。
pthread_t threadID = pthread_self();
if (pthread_equal(threadID, someOtherID) != 0)
/* Branch based on being the same thread */
else
/* Branch based on being different threads */
据我所知,pthread_getunique_np()
返回一个唯一的整数ID,这与使用pthread_t
作为标识符不同。在许多系统上,从pthread_self(3)
和f pthread_getunique_np()
返回的值是相同的。事实上,需要pthread_t
来获得唯一整数。
无论哪种方式,pthread_self(3)
都需要返回调用它的线程的ID,所以我相信您应该能够以您想要的方式使用这个可移植函数。
(有关pthread_getunique_np()
的信息,来自IBM)
_np
后缀的意思是"不可移植"。换句话说,它不是POSIX标准的一部分,因此不能保证在POSIX系统上可用。
只需使用pthread_t
作为唯一标识符。无论如何,我很可能与pthread_getunique_np
的返回值相同。
相关文章:
- C++Union/Struct位域的实现和可移植性
- 具有Qt事件循环的可移植通用共享库设置
- 没有执行策略的 std::transform_reduce 是可移植的吗?
- 如何在 c++ 中正确指定 #include 路径以使程序可移植
- 创建异构顶点数据数组的可移植方法
- FlatBuffers/Protobuf 中是否有支持任意 24 位有符号整数定义的可移植二进制序列化架构?
- 静态库可移植性
- 从非类型模板参数声明 constexpr 数组的可移植方法
- C++:Unicode 字符串文字的可移植性
- 为什么 std::atomic<std::string> 会给出微不足道的可复制错误?
- 如何使Visual Studio 2017 C++项目在计算机之间更具可移植性
- 尝试将 sfml 和 c++ 与 Windows 10 上的可移植 vscode 链接起来
- 在C++中获取命名空间名称的任何可移植技巧
- STR这个实现是否安全且可移植?
- 编写 std::copysign 的可移植 SSE/AVX 版本
- 是可移植的包装结构
- 将参数推送到调用堆栈 (C++) 的可移植方法
- 在为视频游戏实施基本的二进制序列化时,请担心可移植性
- Xcode 8.3.2 中的错误警告:文件的非可移植路径 - 指定的路径与磁盘上的文件名不同
- 使用Visual Studio项目使Opencv可移植,并删除链接错误