检查pthread可取消状态

问题描述 投票:0回答:1

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

谢谢

c pthreads
1个回答
0
投票

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

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

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

int curr_state;
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &curr_state);
pthread_setcancelstate(curr_state, NULL);
//curr_state is the result of your required get
© www.soinside.com 2019 - 2024. All rights reserved.