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 時間後に行う試験の練習問題です。どんな助けでも大歓迎です。私の大学のすべての TA は各自の最終試験で忙しいため、今日はオフィス アワーはありません。
ありがとう