如果我在未使用的pthread_t上调用 pthread_join() 会发生什么
What will happen if I call pthread_join() on an unused pthread_t?
>假设我有一个声明的pthread_t结构,如下所示:
pthread_t newThread;
然后我打电话:
pthread_join(&newThread, NULL, myMethod, NULL);
pthread_join() 会做什么?
根据 ISO C,newThread
变量是一个"不确定值的对象",使用它会触发未定义的行为。它可能有一个触发 CPU 异常的"陷阱表示形式"。
或者它可能只是被解释为该类型的随机值,API 可以通过以下两种方式之一处理该值:要么没有这样的线程,然后返回ESRCH
,要么侥幸有这样的线程。然后出现了各种情况:它是否可以加入,等等。
如果将pthread_join称为未初始化的pthread_t,则行为是未定义的。
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- 警告处理为错误这里有什么问题
- 什么时候调用组成单元对象的析构函数
- #定义c-预处理器常量..我做错了什么
- 努力将整数转换为链表。不知道我在这里做错了什么
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 什么时候在C++中返回常量引用是个好主意
- 当在同一名称空间中有两个具有相同签名的函数时,会发生什么
- C++避免重复声明的语法是什么
- c++库的公共头文件中应该包含什么
- 问题:什么是QAbstractItemView::NoEditTriggers的反面
- 有什么方法可以遍历结构吗
- 当类在C++中定义时,有什么方法可以"register"类吗?
- ifstream什么都没读
- 在C++中,将大的无符号浮点数四舍五入为整数的最佳方法是什么
- 实现无开销push_back的最佳方法是什么
- cMake中的pthread和-pthread选项有什么区别?
- 在 pthread 中运行 shell 命令的良好和优化方法是什么?
- 什么时候使用pthread屏障而不是条件等待和广播更合适
- 如果删除一个正在运行的pthread对象会发生什么?