本文介绍了如何从外部阻止线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

main() {
       
        pthread_t t;
        int k;
      pthread_create(&t,NULL, timer, NULL) // thread is running well.

if(cin >> k) goto point; // when is enter value thread should be closed
        point:
    closegraph(); 
   TerminateThread(&t,0);
   
cout <<"Exiting......";
        getch();
    }

推荐答案


if(cin >> k) goto point; // when is enter value thread should be closed
        point:



如果语句在收到某些输入时始终为true,那么 goto 没有任何意义。你真的应该学会编写没有 goto 语句的代码,它们会导致意想不到的结果。


The if statement will always be true when some input is received so the goto serves no purpose. And you really should learn to write code without goto statements, they can cause unintended results.


这篇关于如何从外部阻止线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 09:12