java - Allowing thread unsafety in arrays -


i have java application performing realtime image processing, image data stored in large int arrays.

updates parts of image array happening multiple threads (this visualisation of high volume stream of incoming events).

readers need take copies of parts of image array display and/or further processing.

because of need high throughput, want avoid expensive synchronisation handle concurrent access. in addition, occasional small visual errors can tolerated, e.g. if reader copies section of image has been partially updated given incoming event. want relax thread safety ensure maximum throughput.

is approach going work? gotchas should aware of?

presumably proposing partition array , allow single thread access each partition. reasonable approach without issue.

in fact fork/join framework , may applicable trying acheive.

e.g. @ javadocs java.util.concurrent.recursiveaction shows example of partitioning array sort it. in nutshell array partitioned until partition size below threshold. each of subsequent partitions partitioned again (ie. recursively).

code looks this:

 class sorttask extends recursiveaction {     final long[] array; final int lo; final int hi;     sorttask(long[] array, int lo, int hi) {     this.array = array; this.lo = lo; this.hi = hi;  }   protected void compute() {     if (hi - lo < threshold)        sequentiallysort(array, lo, hi);     else {        int mid = (lo + hi) >>> 1;        invokeall(new sorttask(array, lo, mid),                  new sorttask(array, mid, hi));        merge(array, lo, hi);     }   } } 

Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -