Multithread filter how to write to the same buffer

Hi all,

I know how to multi-thread works a bit, and I know that the regions of images are passed to different CPU’s core. This process is useful to fill an output image and very convenient. However, I need now to process with multi-thread an image input and check its pixel value and depending on the conditions, store that pixel position in a itk::pointset buffer.

How can I avoid the concurrence to access to pointset buffer from different cores? or If you know a better way to do it, recommendations are welcome :slight_smile:

Thanks in advance.

Are you working with ITKv5?

This pattern would fall into the “map-reduce” pattern.

The recommendation for now, would be in the threaded method, allocate a points buffer, and fill it during while looking over the threads chunk. At the end of the method obtain a lock on a globa or class level point set buffs, and merge the results into it.

1 Like

Thanks for your response.

No, I am working with ITKv4. If I understood your solution is to make a global variable for example a member of the class filter and the end of the multi-thread function make fill it with the solution of the thread executed with a lock method to avoid write at the same position. However, does Itk provide method to do the lock or I should go to low level C/C++ to do it?


You are find a patch which adds a lock here:

And another similar discussion to this type of issue here:

Thanks I will see that.