imglib / imglib2-roi

Regions of interest (ROIs) and labelings for ImgLib2
Other
8 stars 8 forks source link

LabelRegions cannot be used concurrently. #15

Closed tinevez closed 9 years ago

tinevez commented 9 years ago

I found out serependititly that the LabelRegions class, which allows iterating through the labels of a Labeling cannot be used concurrently.

When trying the access a region with a specific label, the cache is update if needed. In multithreaded applications, the cache updated might get called concurrently and this is probably the reason for the error.

The failing method is the private method update https://github.com/imglib/imglib2-roi/blob/master/src/main/java/net/imglib2/roi/labeling/LabelRegions.java#L329

The error stack when trying to access regions concurrently looks like the following:

Exception in thread "[NucleiSplitter] thread 0" java.lang.IndexOutOfBoundsException: Index: 459, Size: 459 at java.util.ArrayList.RangeCheck(ArrayList.java:547) at java.util.ArrayList.get(ArrayList.java:322) at net.imglib2.roi.labeling.LabelRegions.update(LabelRegions.java:361) at net.imglib2.roi.labeling.LabelRegions.getLabelRegion(LabelRegions.java:116) at fiji.plugin.cwnt.segmentation.NucleiSplitter$1.run(NucleiSplitter.java:124)

tinevez commented 9 years ago

My bad. The issue was in another class calling this one.