0
0
Goprogramming~5 mins

Goroutine lifecycle - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a goroutine in Go?
A goroutine is a lightweight thread managed by the Go runtime. It allows functions to run concurrently without the overhead of traditional threads.
Click to reveal answer
intermediate
What are the main states in a goroutine's lifecycle?
The main states are:
  • Created (ready to run)
  • Running (actively executing)
  • Waiting (blocked on I/O, channel, or synchronization)
  • Dead (finished execution)
Click to reveal answer
intermediate
How does a goroutine transition from waiting to running?
When the event it waits for completes (like data on a channel or a timer), the goroutine is moved from waiting to ready, then scheduled by the Go runtime to run.
Click to reveal answer
beginner
What happens when a goroutine finishes its function?
It enters the dead state and is cleaned up by the Go runtime. It no longer consumes CPU or memory resources.
Click to reveal answer
intermediate
Why are goroutines considered lightweight compared to OS threads?
Because goroutines use small stacks that grow and shrink dynamically and are multiplexed onto fewer OS threads by the Go scheduler, making them efficient to create and manage.
Click to reveal answer
Which state is NOT part of the goroutine lifecycle?
ASleeping
BRunning
CWaiting
DDead
What triggers a goroutine to move from waiting to running?
ACompletion of the event it waits for
BManual restart by the programmer
CGarbage collection
DTimeout expiration only
How does the Go runtime manage many goroutines efficiently?
ABy running goroutines sequentially
BBy multiplexing goroutines onto fewer OS threads
CBy pausing all goroutines periodically
DBy creating one OS thread per goroutine
What happens to a goroutine after it finishes execution?
AIt goes back to waiting state
BIt restarts automatically
CIt enters the dead state and is cleaned up
DIt becomes a zombie process
Which of these is a reason goroutines are lightweight?
AThey run only on a single CPU core
BThey require a full OS thread each
CThey cannot communicate with each other
DThey use small, dynamically growing stacks
Describe the lifecycle of a goroutine from creation to termination.
Think about how a goroutine starts, waits, runs, and finishes.
You got /5 concepts.
    Explain why goroutines are more efficient than traditional OS threads.
    Consider resource use and scheduling.
    You got /4 concepts.