title: cancelling a search using threads
body: <p>I am new to multi-threading. I am using c++ on unix. </p>
  
  <p>In the code below, runSearch() takes a long time and I want to be able to kill the search as soon as "cancel == true". The function cancelSearch is called by another thread.</p>
  
  <p>What is the best way to solve this problem?</p>
  
  <p>Thanks you..</p>
  
  <p>------------------This is the existing code-------------------------</p>
  
  <pre><code>    struct SearchTask : public Runnable
      {
          bool cancel = false;
  
          void cancelSearch()
          {
             cancel = true;
          }
  
          void run()
          {
              cancel = false;
              runSearch();
              if (cancel == true)
              {
                  return;
              }
              //...more steps.
          }
      }
  </code></pre>
  
  <p>EDIT: To make it more clear, say runSearch() takes 10 mins to run. After 1 min, cancel==true, then I want to exit out of run() immediately rather than waiting another 9 more mins for runSearch() to complete.</p>