I have two threads, one for data acquisition and the other one for display. In order to avoid from unnecessary synchronization. I use double buffering (or page flipping) as following:
It actually works well but sometimes (1 per 100 frames) I can see tearing in the display which means there is still race condition.
So how can I implement minimal (effective) synchronization of this double buffering? A pseudo algorithm would be enough for me.
You can do this with two semaphores. It is a variation of the Producer/Consumer problem. Pseudo-code in the link I provided.