0
0
Kotlinprogramming~5 mins

Coroutines vs threads mental model in Kotlin - Quick Revision & Key Differences

Choose your learning style9 modes available
Recall & Review
beginner
What is a thread in Kotlin?
A thread is a real operating system unit of execution that runs code independently and can run in parallel with other threads.
Click to reveal answer
beginner
What is a coroutine in Kotlin?
A coroutine is a lightweight, cooperative unit of work that can pause and resume without blocking a thread.
Click to reveal answer
intermediate
How do coroutines differ from threads in resource usage?
Coroutines use much less memory and resources than threads because many coroutines can run on a few threads by suspending and resuming.
Click to reveal answer
intermediate
Explain the mental model of coroutines compared to threads.
Think of threads as real workers who can work at the same time, while coroutines are like tasks that can pause their work and let others run on the same worker.
Click to reveal answer
intermediate
Why are coroutines considered cooperative multitasking?
Because coroutines decide when to pause and resume, they cooperate to share threads without preemptive interruption.
Click to reveal answer
Which of the following best describes a thread?
AA lightweight task that can pause and resume without blocking
BA real OS-level unit of execution that can run in parallel
CA function that runs only on the main thread
DA UI element in Kotlin
What is a key advantage of coroutines over threads?
AThey are lightweight and can suspend without blocking
BThey block threads when waiting
CThey run only on a single thread
DThey use more memory
How do coroutines achieve multitasking?
ABy blocking the main thread
BBy running on separate CPU cores simultaneously
CBy creating new threads for each task
DBy cooperating and suspending to share threads
Which statement is true about threads and coroutines?
AThreads are lighter than coroutines
BCoroutines always run on separate threads
CCoroutines can run many tasks on fewer threads
DThreads cannot run in parallel
Why are coroutines called cooperative multitasking?
ABecause they decide when to pause and resume
BBecause they preempt threads forcibly
CBecause they run only on the main thread
DBecause they block other coroutines
Explain the difference between coroutines and threads using a simple real-life analogy.
Think about workers and tasks sharing time.
You got /3 concepts.
    Describe why coroutines are more efficient than threads for many small tasks.
    Focus on how coroutines save memory and CPU.
    You got /3 concepts.