マルチスレッドのプログラミング

pthread_setcanceltype の構文

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);

スレッドが生成されると、デフォルトでは取り消しタイプが遅延モードに設定されます。遅延モードにあるスレッドは、取り消しポイント以外では取り消すことができません。非同期モードにあるスレッドは、実行中の任意のポイントで取り消すことができます。非同期モードを使用するのは好ましくありません。