title: c++ - how to know when the thread context switch happens?
body: <p>Like the title says how do we know when does the context switch happens when using std::threads in c++</p>
  
  <p>for example </p>
  
  <pre><code>void a()
  {
     //some code
  }                                    
  void b(); 
  {
     //some code 
  }                                    
  
  int main ()
  {
    thread th1 (a);       
    thread th2 (b); 
  
    th1.join();                                        
    th2.join();                                       
  
    return 0;
  } 
  </code></pre>
  
  <p>is there a way to know when the O.S makes the thread switch and we could actually depict like print a or b when the respective function is processing.</p>
  
  <p>Note: I've used mutexes and control variables putting a simple cout&lt;&lt;"a is being processed" on them doesn't necessarily depict the real context switch. </p>