title: Multi core, make function called from inside function to run on second core. directshow, opencv
body: <p>So, I've been working on a real time tracking system with opencv. A couple of days ago I had to start using directshow (which was totally new for me) because I needed higher resolution from the webcam. With higher resolution comes higher cpu usage. the cpu is running at 50% when only using directshow without ANY opencv algorithms. (I have dual core = 100% usage of one core)</p>
  
  <p>So now I need to expand this system so that is uses both of my cores.</p>
  
  <p>I found this nice example from microsoft And was able to run it, using both of my cores:</p>
  
  <pre><code>void test1(){
      parallel_invoke(
          []() { run1(); },
          []() { run2(); }
      );
  }
  </code></pre>
  
  <p>This runs perfectly and I am able to use about 85% of the total cpu (with just 2 functions with loops 'n stuff).
  Now I want to use this in my other system. And I don't know how to do it.</p>
  
  <p>Short description of my system:</p>
  
  <pre><code>int main(){
       startDirectshow()
  };
  
  startDirectShow(){
       //code for creating the directshow filter graph. including iSampleGrabber filter.
  }
  
  sampleCallBackFunction(....){
        // function called for every frame in the graph
  }
  </code></pre>
  
  <p>Every thing is working so far, The sampleCB is called for every frame(or at least multiple frames per second, frames might be missed when using this?!)</p>
  
  <p>My idea was to let the "sampleCallBackFunction()" run on the second core (I dont want to lock it to a specific core, only use first one available)</p>
  
  <p>But the example I found starts both functions at the same time, from the same place. is it possible to, in some way, to tell the system that "sampleCallBackFucntion" should be running on another core?</p>
  
  <p>Another idea i had, was to just store the data in "sampleCallBackFunction()", and also set a bool "newFrameAvailable", to true. And let another thread pull data from a global array. </p>
  
  <pre><code>while(true)
      If (newFrameAvailable){
           get-next-frame-in-buffer-and-do-opencv-algorithm();
      }
      else{
           do-nothing();
      }
  }
  </code></pre>
  
  <p>So. My question: How to make a function called from inside another function ("sampleCallBackFunction" is called from "startDirectshow")?</p>
  
  <p>Thanks!</p>