I have a Java application that is performing some realtime image processing, with the image data stored in large int arrays.
Updates to parts of the image array are happening constantly from multiple threads (this is basically for visualisation of a very high volume stream of incoming events).
Readers need to take copies of parts of the image array for display and/or further processing.
Because of the need for high throughput, I want to avoid any expensive synchronisation to handle the concurrent access. In addition, occasional small visual errors can be tolerated, e.g. if a reader copies a section of the image that has only been partially updated for a given incoming event. Basically what I want to do is relax thread safety to ensure maximum throughput.
Is this approach going to work? Any gotchas I should be aware of?
Presumably you are proposing to partition the array and allow only a single thread to access each partition. This is a reasonable approach without issue.
In fact the fork/join framework does this and may be applicable to what you are trying to acheive.
e.g. Look at the javadocs for java.util.concurrent.RecursiveAction which shows an example of partitioning an array to sort it. In a nutshell the array is partitioned until the partition size is below a threshold. Each of the subsequent partitions are then partitioned again (ie. recursively).
Code looks like this: