// disable cancelability
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE,&OldState);
for(int Count = 1;Count < 100;Count++)
{
cout << «thread A is working: " << Count << endl;
}
}
void *task2(void *X)
{
int OldState,OldType;
// enable cancelability, asynchronous
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,&OldState);
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,&OldType);
for(int Count = 1;Count < 100;Count++)
{
cout << «thread B is working: " << Count << endl;
}
}
void *task3(void *X)
{
int OldState,OldType;
// enable cancelability, deferred
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,&OldState);
pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED,&OldType);
for(int Count = 1;Count < 1000;Count++)
{
cout << «thread C is working: " << Count << endl;
if((Count%100) == 0){
pthread_testcancel();
}