pthread_setcanceltype子例程在原子上都将调用线程的可取消类型设置为所指示的类型,并在oldtype引用的位置返回先前的可取消类型。 类型的合法值为 PTHREAD_CANCEL_DEFERRED 和PTHREAD_CANCEL_异步。 任何新创建的线程 (包括首次调用main的线程) 的可取消状态和类型分别为 PTHREAD_CANCEL
pthread_setcanceltype子常式會自動將呼叫執行緒的可取消性類型設為指出的類型,並在oldtype所參照的位置傳回前一個可取消性類型。 類型的合法值為 PTHREAD_CANCEL_DEFERRED 及 PTHREAD_CANCEL_ASYNCHRONOUS。 任何新建立之執行緒的可取消性狀態及類型 (包括第一次呼叫main的執行緒) 分別為 PTHREAD_CANCE...
int oldtype; pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype);//设置为同步取消,这样保证push和其他操作不能被打断 pthread_cleanup_push(routine, arg); ... pthread_cleanup_pop(execute); pthread_setcanceltype(oldtype, NULL); }
Prototype: int pthread_setcanceltype(int type, int *oldtype);#include <pthread.h> int oldtype; int ret; /* deferred mode */ ret = pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype); /* async mode*/ ret = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);...
the initial thread. The thread's cancelability type determines when a cancelable thread will respond to a cancellation request. PTHREAD_CANCEL_DISABLE The thread is not cancelable. If a cancellation request is received, it is blocked until cancelability is enabled. The pthread_setcanceltype() ...
由pthread_setcanceltype(3) 决定的线程的取消类型可以是异步的,也可以是延迟的(新线程的默认值)。异步可取消性意味着线程可以在任何时候被取消(通常是立即取消,但系统不保证这一点)。延迟取消类型意味着取消将被延迟,直到线程接下来调用一个作为取消点的函数。在 pthreads(7) 中提供了一个函数列表,这些函数是或...
查看老吴的代码,这两条不需要写,因为这个两个属性是默认的! pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,NULL); pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED,NULL); 1. 2. 老吴的文章: Linux-C编程 / 多线程 / 如何终止某个线程?...
int pthread_setcanceltype(int type, int *oldtype);void pthread_testcancel(void);Cancellation是一种一个线程可以结束另一个线程执行的机制。更确切的说,一个线程可以发生Cancellation请求给另一个线程。 根据线程的设置,收到请求的线程可以忽视这个请求,立即执行这个请求或者延迟到一个cancellation点执行。 当一个...
如果你想获取旧的取消类型,就需要传入一个指向整型变量的指针作为参数。如果你不关心旧的取消类型,可以...