title: Kotlin Multiplatform concurrent mutability iOS vs Android
body: <p>I'm aware that Kotlin/Native has very specific rules in regards to <a href="https://kotlinlang.org/docs/kmm-concurrency-overview.html" rel="nofollow noreferrer">mutability of objects between threads</a>.</p>
  <p>However to my surprise, I've found that when running unit tests from commonMain (deployed to androidTestDebug), <strong>I am able to change mutable states on different threads</strong>. For example this works fine when changing the value in <code>MyData</code>:</p>
  <pre><code>data class MyData(var value : Int = 0)
  
  suspend fun main() = coroutineScope {
    val myData = MyData()
    val newContext1 = newSingleThreadContext(&quot;contextOne&quot;)
    val newContext2 = newSingleThreadContext(&quot;contextTwo&quot;)
  
    launch (newContext1) {
      myData.value = 1
    }
    launch (newContext2) {
      myData.value = 2
    }
  }
  </code></pre>
  <p>However if I run this while targeting iOS, it crashes, giving me <code>kotlin.native.concurrent.InvalidMutabilityException</code>. This is what I would expect to happen on both platforms. I'm new to KMM, but <strong>why aren't concurrent mutability rules enforced when running commonMain code on JVM</strong>?</p>
  <p>Also <strong>is there a way to force mutability rules on the JVM so that tests fail on Android just as they would on iOS</strong>? I think this would help ensure platform consistency.</p>