I am a beginner using multithreading in C++, so I'd appreciate it if you can give me some recommendations.
I have a function which receives the previous frame and current frame from a video stream (let's call this function, readFrames()). The task of that function is to compute Motion Estimation.
The idea when calling readFrames() would be:
- Store the previous and current frame in a buffer.
- I want to compute the value of Motion between each pair of frames from the buffer but without blocking the function
readFrames(), because more frames can be received while computing that value. I suppose I have to write a functioncomputeMotionValue()and every time I want to execute it, create a new thread and launch it. This function should return somefloat motionValue. - Every time the
motionValuereturned by any thread is over a threshold, I want to +1 a common int variable, let's call itnValidMotion.
My problem is that I don't know how to "synchronize" the threads when accessing motionValue and nValidMotion.
Can you please explain to me in some pseudocode how can I do that?
nValidMotionatomic and any access to it will be synchronized automatically.