看到我可以使用 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/