Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Precautions for simultaneous read and write of an image?

I've got two parallel asynchronous loops. One reads images and writes to an image variable (either monochrome or colour U8). The other reads the image variable and processes it periodically.

 

Do I need to take precautions to avoid reading and writing simultaneously? And if so, what might be a good way to do this?

 

Thanks

0 Kudos
Message 1 of 5
(5,274 Views)
Can you be more specific on write of an image (what you are writing) ??
-I think it's never good in any software practice to do both write and read from one single source.
-If you are trying to write to the same image while some thing else is reading it'll obviously lead to race condition and you are never sure of what image you are reading/writing.
-One thing, use extra copy of image(can be) and use it for processing.
Thanks
uday
0 Kudos
Message 2 of 5
(5,271 Views)

I agree. I wanted to check whether the image variable type (as it's call-by-reference) had specific protection built-in within LabView to prevent simultaneous reading and writing. E.g. does whichever operation starts first lock it until completed?

 

I'm reading from a camera in one loop, and processing asynchronously in another.

 

I've written in a semaphore system (using local variables though), but maybe don't need it. Less complexity is better.

0 Kudos
Message 3 of 5
(5,269 Views)
For basic code using standard Vision functions to interact with the images, there is locking in place to prevent simultaneous reading and writing to the same image. Some edge cases where this breaks are if you use an IMAQ ring with Extract or Map Pixel Pointer functions to provide direct access to the image to 3rd party code.

However, these internal locks only cover a single operation at a time. If you call multiple VIs in a row that read or write to the image, there is nothing to ensure that the image isn't accessed by other code in-between. Since most code uses more than one operation, this means that you likely want to somehow synchronize access at a higher level.

Message 4 of 5
(5,244 Views)

Thanks - that's useful. I was periodically getting "... is not an image" or "... is not the right size ..." errors, and 2 force quits of LabView, which made me wonder if it was possible to do bad things at the system level by reading and writing simultaneously. I've not got to the bottom of why it was happening yet in my code, but I think that switching to a functional global for the first part of the image copy / processing makes sense anyway and that may fix it.

0 Kudos
Message 5 of 5
(5,236 Views)