While loop checking for new frames in kinect using complete CPU

Hey everyone,

The title of this post might not be very clear, because i find this problem to be rather complicated to explain:

I created a separate thread using c++11 std::thread to retrieve, and process depth images from ofxKinect. Because the thread is not limited to a certain frame rate like the main thread running open frameworks, my while loop checking whether new frames are available from the kinect eats up a complete core of my cpu.

The code looks something like this: (sorry for points, somehow spaces get deleted)

int KinectThread::threadMain() {
…while (kinect.isConnected()) {
…if (grabImage()) { // grabImage is a function that tries to grab a new frame from the kinect, if this succeeds it returns true.
…findContours(); // findcontours is a function that implements openCv
…}
… }
}

I was wondering what the best way is to not have “while (kinect.isConnected())” run as fast as possible, but instead wait for either a mutex condition of an event or something similar to execute. Preferably also changing the ofxKinect addon’s source code.

Many thanks,
Aart