void cleanupHandler(void *arg) {
printf("In the cleanup handler\n");
}
void *Thread(void *string) {
int i;
int o_state;
int o_type;
pthread_cleanup_push(cleanupHandler, NULL);
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &o_state);
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &o_type);
puts("1 Hello World");
pthread_setcancelstate(o_state, &o_state);
puts("2 Hello World");
pthread_cleanup_pop(0);
pthread_exit(NULL);
}
int main() {
pthread_t th;
int rc;
rc = pthread_create(&th, NULL, Thread, NULL);
pthread_cancel(th);
pthread_exit(NULL);
}
我想知道这段代码的输出是什么以及它们会以什么顺序发生。是的,这是我 6 小时后考试的练习题。任何帮助将不胜感激。今天没有办公时间,因为我大学的所有助教都忙于自己的期末考试。
谢谢