I am new to Android Coroutines. I've been reading about it from the official docs and found this note
Important: Using a dispatcher that uses a thread pool like Dispatchers.IO or Dispatchers.Default does not guarantee that the block executes on the same thread from top to bottom. In some situations, Kotlin coroutines might move execution to another thread after a suspend-and-resume. This means thread-local variables might not point to the same value for the entire withContext() block.
but I didn't get this specific sentence
This means thread-local variables might not point to the same value for the entire withContext() block
Can anyone show me an example of this scenario?
withContext(IO) { println(currentThread().name; delay(100); println(currentThread().name }You can substitutecurrentThread()for any otherThreadLocal-backed value. - Marko Topolnik