使用setjumploopjump在线程中跳转的问题使用setjump到另一个线程中跳转,跳转成功了,后面的代码不执行了#define_CRT_SECURE_NO_WARNINGS#include #include #include #include #include #include #include jmp_bufbuf;void*print_a(void*);void*print_b(void*);//线程A方法void*print_a(void*a){for(inti=0;i<5;++i){sleep(1);printf("aaaa\n");intjmpret=setjmp(buf);if(!jmpret){printf("!jmpret\n");}else{printf("继续执行线程1\n");}}returnNULL;}//线程B方法void*print_b(void*b){for(inti=0;i<5;++i){sleep(1);printf("bbbb\n");if(i==3){printf("进入线程2\n");longjmp(buf,1);}}returnNULL;}intmain(){pthread_tt0;pthread_tt1;//创建线程Aif(pthread_create(&t0,NULL,print_a,NULL)==-1){printf("failtocreatepthreadt0\n");exit(1);}if(pthread_create(&t1,NULL,print_b,NULL)==-1){printf("failtocreatepthreadt1\n");exit(1);}//等待线程结束void*result;if(pthread_join(t0,&result)==-1){printf("failtorecollectt0\n");exit(1);}else{printf("t0success\n");}if(pthread_join(t1,&result)==-1){printf("failtorecollectt1\n");exit(1);}else{printf("t1success\n");}getchar();return0;}主线程的getchar也不执行了这是为何?
一只萌萌小番薯
慕桂英3389331
相关分类