检查 pthread 可取消状态

标签 c pthreads

看到我可以使用 pthread_setcancelstate 来设置给定 pthread 的可取消性。 (启用或禁用它)。 但是,我找不到匹配的“pthread_getcancelstate”函数来检查给定 pthread 的可取消状态。任何建议将不胜感激。

谢谢

最佳答案

http://man7.org/linux/man-pages/man3/pthread_setcanceltype.3.html

根据手册页设置状态也将获得它配置的旧状态.. 在这方面,一个简单的获取操作可以是设置一个状态,然后将状态设置回旧状态 - 我怀疑这会影响你的逻辑

您在第二次调用时设置的状态是线程所处的状态:

int curr_state;
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &curr_state);
pthread_setcancelstate(curr_state, NULL);
//curr_state is the result of your required get

关于检查 pthread 可取消状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49095599/

相关文章:

c - 二叉树节点以及与父节点的关系

c++ - 删除 pthread_t*

c - 在 C 中的两个函数上使用 pthreads

c - 如何将网格传递给 "void my_func(void *args)"

找不到 -lpthread?

c++ - 多线程概念题

C++ Windows 添加选项到菜单

c - system() with evince 永远不会返回

c - C中同时独立执行两个函数

c - 系统调用表中的common abi有什么用