Avatar ·

What is the difference between a Thread and a Coroutine in Kotlin?

Hi everyone! I started learning Kotlin and coroutines, but I can't understand the fundamental difference between a regular Thread and a Coroutine. It seems like both allow you to execute code in parallel or asynchronously. I read the documentation, but it's written in a complicated way. For example, I wrote a simple example with threads: ```kotlin fun main() { println("Main starts: ${Thread.currentThread().name}") val thread = Thread { println("Thread working: ${Thread.currentThread().name}") Thread.sleep(1000) println("Thread done") } thread.start() println("Main continues: ${Thread.currentThread().name}") thread.join() println("Main ends") } ``` And the equivalent with coroutines: ```kotlin fun main() = runBlocking { print