1 // This file was automatically generated from coroutine-context-and-dispatchers.md by Knit tool. Do not edit. 2 package kotlinx.coroutines.guide.exampleContext11 3 4 import kotlinx.coroutines.* 5 6 val threadLocal = ThreadLocal<String?>() // declare thread-local variable 7 <lambda>null8fun main() = runBlocking<Unit> { 9 threadLocal.set("main") 10 println("Pre-main, current thread: ${Thread.currentThread()}, thread local value: '${threadLocal.get()}'") 11 val job = launch(Dispatchers.Default + threadLocal.asContextElement(value = "launch")) { 12 println("Launch start, current thread: ${Thread.currentThread()}, thread local value: '${threadLocal.get()}'") 13 yield() 14 println("After yield, current thread: ${Thread.currentThread()}, thread local value: '${threadLocal.get()}'") 15 } 16 job.join() 17 println("Post-main, current thread: ${Thread.currentThread()}, thread local value: '${threadLocal.get()}'") 18 } 19