What thread is interrupted?

Report a typo

What is the output of this snippet?

import java.lang.Thread.sleep

fun main() {
    val thread = thread(start = false, block = {
        while (Thread.currentThread().isInterrupted) {
            try {
                sleep(2000)
            } catch (e: InterruptedException) {
                Thread.currentThread().interrupt()
            }
        }
    })
    thread.start()
    thread.interrupt()
    println(Thread.currentThread().isInterrupted)
}

fun thread(
    start: Boolean,
    block: () -> Unit
): Thread {
    val thread = object : Thread() {
        override fun run() {
            block()
        }
    }
    return thread
}
Enter a short text
___

Create a free account to access the full topic