Adam S
06/16/2024, 9:31 AM(/opt/buildAgent/work/b2e1db4d8d903ca4/kotlin/libraries/stdlib/native-wasm/src/kotlin/collections/AbstractMutableList.kt:138:23)
at 5 exampleAudioMixedProcessor.kexe 0x1029658cb kfun:kotlin.collections.AbstractMutableList.IteratorImpl.next#internal + 151
Why might Kotlin Native be using Wasm?Adam S
06/16/2024, 9:31 AMUncaught Kotlin exception:
kotlin.ConcurrentModificationException
at 0 exampleAudioMixedProcessor.kexe 0x1029348ff kfun:kotlin.Exception#<init>(kotlin.String?;kotlin.Throwable?){} + 143 (/opt/buildAgent/work/b2e1db4d8d903ca4/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Exceptions.kt:25:70)
at 1 exampleAudioMixedProcessor.kexe 0x102934a97 kfun:kotlin.RuntimeException#<init>(kotlin.String?;kotlin.Throwable?){} + 143 (/opt/buildAgent/work/b2e1db4d8d903ca4/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Exceptions.kt:36:70)
at 2 exampleAudioMixedProcessor.kexe 0x1029356e3 kfun:kotlin.ConcurrentModificationException#<init>(kotlin.String?;kotlin.Throwable?){} + 143 (/opt/buildAgent/work/b2e1db4d8d903ca4/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Exceptions.kt:175:65)
at 3 exampleAudioMixedProcessor.kexe 0x102935757 kfun:kotlin.ConcurrentModificationException#<init>(){} + 95 (/opt/buildAgent/work/b2e1db4d8d903ca4/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Exceptions.kt:178:35)
at 4 exampleAudioMixedProcessor.kexe 0x102965ccb kfun:kotlin.collections.AbstractMutableList.IteratorImpl.checkForComodification#internal + 211 (/opt/buildAgent/work/b2e1db4d8d903ca4/kotlin/libraries/stdlib/native-wasm/src/kotlin/collections/AbstractMutableList.kt:138:23)
at 5 exampleAudioMixedProcessor.kexe 0x1029658cb kfun:kotlin.collections.AbstractMutableList.IteratorImpl.next#internal + 151 (/opt/buildAgent/work/b2e1db4d8d903ca4/kotlin/libraries/stdlib/native-wasm/src/kotlin/collections/AbstractMutableList.kt:120:13)
at 6 exampleAudioMixedProcessor.kexe 0x1029aa573 kfun:kotlin.collections.Iterator#next(){}1:0-trampoline + 99 (/opt/buildAgent/work/b2e1db4d8d903ca4/kotlin/libraries/stdlib/native-wasm/src/kotlin/collections/Iterator.kt:18:21)
at 7 exampleAudioMixedProcessor.kexe 0x1028823f3 kfun:audio_mixed_processor#main(){} + 2843 (/[...]/examples/src/audio/audio_mixed_processor.kt:<unknown>)
at 8 exampleAudioMixedProcessor.kexe 0x1028829a7 Konan_start + 111 (/[...]/examples/src/audio/audio_mixed_processor.kt:53:1)
at 9 exampleAudioMixedProcessor.kexe 0x10288cafb Init_and_run_start + 107
at 10 dyld 0x1831920df start + 2359
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':documentation:examples:runExampleAudioMixedProcessorDebugExecutableMacosArm64'.
> Process 'command '/[...]/examples/build/bin/macosArm64/exampleAudioMixedProcessorDebugExecutable/exampleAudioMixedProcessor.kexe'' finished with non-zero exit value 134
Oleg Yukhnevich
06/16/2024, 10:01 AMWhy might Kotlin Native be using Wasm?It’s not, there are stdlib sources that are shared between wasm and native AFAIR there were some changes in Kotlin 2.0 regarding improving performance and stability of collections for K/N So there are 2 variants: 1. It’s a bug in new implementation (probably not) 2. It’s a bug in your code, because previously there were no check for mutation Also, concurrent modification exception could be not only in case of concurrency F.e if when iterating a list you are removing/adding item to itself
Adam S
06/16/2024, 10:33 AMAdam S
06/16/2024, 10:34 AMAdam S
06/16/2024, 10:36 AMstaticCFunction()
now run in a background process...Oleg Yukhnevich
06/16/2024, 10:37 AMAdam S
06/16/2024, 10:38 AMAdam S
06/16/2024, 10:41 AMOleg Yukhnevich
06/16/2024, 10:42 AMAdam S
06/16/2024, 10:42 AMAdam S
06/16/2024, 11:42 AMprocessor()
is called by C and updates a global mutable list. It worked in 1.9.24, but after updating to 2.0.0 I get a ConcurrentModificationException
private val averages = ArrayDeque<Float>(400)
private fun processor(frames: List<Float>) {
val average = frames.average().toFloat()
// Moving history to the left
while (averages.size >= 400) {
averages.removeFirst()
}
// Adding last average value
averages.addLast(average)
}
Even if I try and update the averages atomically using a MutableStateFlow, then I still get a ConcurrentModificationException
private val averages = MutableStateFlow(ArrayDeque<Float>(400))
private fun processor(frames: List<Float>) {
val average = frames.average().toFloat()
averages.update { value ->
// Moving history to the left
while (value.size >= 400) {
value.removeFirst()
}
// Adding last average value
value.addLast(average)
value
}
}
Oleg Yukhnevich
06/16/2024, 12:00 PMaverageVolume.forEachIndexed
usage below - which cause the error, as most probably callback (processAudio
) can be called concurrently, right?Michael Paus
06/18/2024, 11:48 AMAdam S
06/18/2024, 4:36 PM