c++ - Output for simple program using pthread -
void cleanuphandler(void *arg) { printf("in 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); } i wondering output of code , in order happen. yes, practice test question exam have in 6 hours. appreciated. there no office hours today of ta's college busy own finals.
thanks
here man pages need understand problem putting on exam (which won't exact problem above.) need understand each of functions does.
- http://man7.org/linux/man-pages/man3/pthread_cleanup_push.3.html
- http://man7.org/linux/man-pages/man3/pthread_setcanceltype.3.html,
- http://man7.org/linux/man-pages/man3/pthread_cancel.3.html
cleanup_pushpushs handler on stack of functions called if calling thread cancelled or exits.setcancelstatetemporarily locks out cancels (so can callsetcanceltypeatomically without weirdness happening.)setcanceltypeallows/disallows asynchronous cancellation notification.cancelattempts cancel other thread.exitexits calling thread.you need understand whether
pthread_setcancelstatecancellation point. find information either on above man pages or on http://man7.org/linux/man-pages/man7/pthreads.7.html.
in question (and presumably similar 1 on exam), need enumerate possible interleavings of calls these functions between 2 threads.
Comments
Post a Comment