Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C++
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();
    }
Posted
Updated 3-Jan-15 18:37pm
v2

A global variable or better an event which is checked in the thread. By that method you can do some cleanup like handles or memory and terminate clean and smooth.
 
Share this answer
 
'badly' is the answer - its dangerous - the best way is to have perhaps an eventhandle, check that periodically in the thread's working procedure/loop, and if its flagged (by signalling/raising it from outside the thread), exit the thread cleanly from within
 
Share this answer
 
C++
if(cin >> k) goto point; // when is enter value thread should be closed
        point:

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900