title: How to safely close a THREAD which has a infinite loop in it
body: <p>I am creating a thread using <code>_beginthreadex</code> function. The function address I am passing in it has an infinite while loop (<code>while(1)</code>) . I have the <code>threadid</code> and <code>threadhandle</code>.</p>
  
  <p>I can use <code>TerminateThread(threadhandle,1);</code> But it is dangerous.   </p>
  
  <p>The safe way is to kill thread using <code>_endthreadex</code> but it can only be used from inside the thread, and I wanted to kill the thread from outside.</p>
  
  <p>So please suggest if there is a safe way to close,end or kill the thread safely from outside using <code>threadid</code> or <code>threadhandle</code>.</p>