Skip to Main Content
Hands-On Object-Oriented Programming with Kotlin
book

Hands-On Object-Oriented Programming with Kotlin

by Abid Khan, Igor Kucherenko
October 2018
Intermediate to advanced content levelIntermediate to advanced
370 pages
9h 15m
English
Packt Publishing
Content preview from Hands-On Object-Oriented Programming with Kotlin

Coroutines and threads

An instance of the Thread class represents a native thread in the corresponding operating system when a program is running. This means that each instance of the Thread consumes memory for its stack and needs time to be initialized. If you are familiar with multithreaded programming, you know that switching between the contexts of threads is a pretty expensive operation, which is why it makes no sense to invoke short-term tasks in a separate thread.

In Kotlin, a coroutine is a pure language abstraction. Coroutines refer to objects in the memory heap and switching between coroutines doesn't involve operating system kernel operations. You can use a coroutine in the same way as a thread. This means that a coroutine contains ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Functional Programming in Kotlin

Functional Programming in Kotlin

Runar Bjarnason, Paul Chiusano, Marco Vermeulen
Learning Concurrency in Kotlin

Learning Concurrency in Kotlin

Miguel Angel Castiblanco Torres

Publisher Resources

ISBN: 9781789617726Supplemental Content