Charlie Tapping
11/24/2023, 9:12 PM@ThreadLocal
private var idx: Int? = null
private class NativeReadEpochIndex(val initializer: () -> Int) : ReadEpochIndex {
override fun value(): Int {
if (idx == null) {
idx = initializer()
}
return idx!!
}
}
and I’m storing the instantiated class in a reference and calling the value function from two different threads. The first thread is the thread the test runs on and the second is a pthread I have spun up. I have checked and the calls do occur on different threads as they have different ids but somehow idx is not actually threadlocal when run with allTests despite that test only existing in a native package. I’ve printed out idx on both threads and it is certainly being shared across threads? The test in question is here .