在 pthread_t 为数字的平台上,0 保证为无效值

On platforms where pthread_t is numeric, is 0 guaranteed to be an invalid value?

本文关键字:无效 平台 pthread 数字      更新时间:2023-10-16

pthread_t(由 pthread_self() 返回(是一种不透明的类型,但在某些平台上实际上是数字,例如 typedef ed to unsigned long 。在这些平台上,0是否是无效的pthread_t值?-1呢?

如果我想要一个pthread_t或无效的值,我会使用 C++1y 中的boost::optional<pthread_t>std::optional<pthread_t>

这具有很少的开销(字节(,表示我想要的内容(此值可能是也可能不是pthread_t(,并且不依赖于特定于平台的行为。