1 /* 2 * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 */ 4 5 // This file was automatically generated from coroutine-context-and-dispatchers.md by Knit tool. Do not edit. 6 package kotlinx.coroutines.guide.exampleContext11 7 8 import kotlinx.coroutines.* 9 10 val threadLocal = ThreadLocal<String?>() // declare thread-local variable 11 <lambda>null12fun main() = runBlocking<Unit> { 13 threadLocal.set("main") 14 println("Pre-main, current thread: ${Thread.currentThread()}, thread local value: '${threadLocal.get()}'") 15 val job = launch(Dispatchers.Default + threadLocal.asContextElement(value = "launch")) { 16 println("Launch start, current thread: ${Thread.currentThread()}, thread local value: '${threadLocal.get()}'") 17 yield() 18 println("After yield, current thread: ${Thread.currentThread()}, thread local value: '${threadLocal.get()}'") 19 } 20 job.join() 21 println("Post-main, current thread: ${Thread.currentThread()}, thread local value: '${threadLocal.get()}'") 22 } 23