I am working on an image processing application where I have two threads on top of my main thread:
1 - CameraThread , which captures images from a webcam and writes them to the clipboard
2 - ImageProcessingThread , which takes the last image from this buffer for filtering.
The reason this is multithreading is because speed is critical, and I need CameraThread to continue to capture images and make the last capture ready to capture using ImageProcessingThread while it is still processing the previous image.
My problem is finding a quick and thread-safe way to access this regular buffer, and I realized that ideally it should be a triple buffer (image [3]), so if ImageProcessingThread is slow, then CameraThread can continue to write on two other images and vice versa.
Which locking mechanism would be most suitable for this to be thread safe?
I looked at the lock statement, but it looks like it will make a block of threads, expecting one more to be completed, and that will be against the triple buffering point.
Thanks in advance for any idea or advice.
J.
source
share