# kotlin-native

Charlie Tapping

11/24/2023, 9:12 PM
I have a really odd issue involving the kotlin.native.concurrent.ThreadLocal annotation when run inside of gradle tests It seems to work when invoking a test directly from the ide but fails when I run the allTests gradle task? Essentially I have a class like this:
Copy code
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 .