You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
KernelDispatch / KernelRegistry are not safe for concurrent reads #1259
KernelDispatch (skainet-backend-api) keeps its kernel table in a plain MutableList and guards auto-install with an unsynchronized var autoInstallAttempted; KernelRegistry does the same with its provider list. KernelDispatch.matmul calls ensureInstalled() and find(key) on every dispatch, so two threads dispatching at once (e.g. per-head attention tasks, or two forwards on two contexts) can race: ConcurrentModificationException from ArrayList, a double auto-install, or a lost registration.
Where
skainet-backends/skainet-backend-api/src/commonMain/kotlin/sk/ainet/backend/api/kernel/KernelDispatch.kt — kernels: MutableList, ensureInstalled(), register(), var defaultSink
Immutable snapshots replaced wholesale under a lock (@Volatile list + a @OptionalExpectationJvmSynchronized that actualizes to kotlin.jvm.Synchronized on JVM/Android and is a no-op elsewhere). Reads stay lock-free. Covered by KernelDispatchConcurrencyTest (16 threads registering/finding; contended ensureInstalled() runs once).
Activity
michalharakal commentedon Sep 4, 2026
Fixed in #1262 (merged):
KernelDispatch/KernelRegistrynow hold volatile immutable snapshots with synchronized writes (KernelDispatchConcurrencyTest).