Thursday, October 16, 2008

Ptherad Cancelability

Ptherad Cancelability 的标准说明见: POSIX.1 2.9.5 Thread Cancellation.

相关接口有:
int pthread_setcancelstate(int state, int *oldstate);
int pthread_setcanceltype(int type, int *oldtype);
void pthread_testcancel(void);

其中:
pthread_setcancelstate 来控制是否允许 cancel.
pthread_setcanceltype 用来控制 Ptherad Cancelability Type: 有deferred 和 asynchronous 两种. deferred 的实现方式为当调用 pthead_cancel时, 在pthread 管理结构中置上一个标志, pthread调用一些libc库函数时,会默认检测和处理这个标志, 也可以显示调用pthread_testcancel 来检测并处理这个标志. asynchronous 的实现方式为 通过 tgkill 系统调用来发送 SIGCANCEL 信号(此信号不能通过pthead_kill发送,无法通过参数检查).

No comments: