PDA

View Full Version : Visualization and Threads



^NyAw^
9th October 2009, 11:36
Hi,

I've developed an application that uses 2 QThreads to capture and process images captured from a camera(live capture):
-First thread capture images from a camera
-Second thread process the images
-The two threads share the same image buffer(with QWaitCondition to lock them)
-Main thread recives pointer to image buffer to display them

To speed up the process the process thread emits a pointer to the image buffer to display.
The problem is that the capture and process threads are well synchronized but the main thread can stay displaying the image when the capturing thread writes a new image on the same image pointer. Then the application crash(only using multiple CPUs, but is normal that on a signle CPU to not crash).
One solution is to emit images as copy instead of pointer but it decreases a lot the application performance.

Any idea how to lock the capture thread when the main thread is displaying the image and viceversa?

Thanks,

spud
12th October 2009, 14:13
One solution is to emit images as copy instead of pointer but it decreases a lot the application performance.
Have you actually tried this? QImage's copy-on-write mechanism makes passing QImages by value virtually a no-op.