QutEcoacoustics / audio-analysis

The audio analysis code (AnalysisPrograms.exe) for the QUT Ecoacoustics Research Group
https://ap.qut.ecoacoustics.info/
Apache License 2.0
52 stars 12 forks source link

Parallelisation bug mono/file system #32

Closed atruskie closed 9 years ago

atruskie commented 9 years ago

For accessing the IndexProperties.yml there is a Concurrent dictionary that should allow parallel and coordinated reading and caching of the properties.

Works on windows, fails on mono.

System.IO.IOException: Sharing violation on path /home/ubuntu/bioacoustics/workers/analysis/AP/ConfigFiles/IndexPropertiesConfig.yml
at System.IO.FileStream..ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,int,bool,System.IO.FileOptions) <IL 0x00338, 0x00607>
at System.IO.FileStream..ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare) <IL 0x0000d, 0x0004b>
at (wrapper remoting-invoke-with-check) System.IO.FileStream..ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare) <IL 0x0001e, 0x00067>
at System.IO.FileInfo.Open (System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare) <IL 0x00009, 0x00053>
atruskie commented 9 years ago

Diagnosed: Concurrent dictionary allows the value to be created multiple times by different threads, but only one value will be stored.

On mono, apparently opening the same file (Read mode and Share) results in an System.IO.IOException.

Solution change the ConcurrentDictionary to a proper lock - slower but prevents the file from ever being read twice.