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?
✗ Incorrect
Goroutines do not have a 'Sleeping' state; they are either running, waiting (blocked), or dead.
What triggers a goroutine to move from waiting to running?
✗ Incorrect
When the awaited event (like channel data or timer) completes, the goroutine becomes ready to run.
How does the Go runtime manage many goroutines efficiently?
✗ Incorrect
The Go scheduler multiplexes many goroutines onto a smaller number of OS threads to save resources.
What happens to a goroutine after it finishes execution?
✗ Incorrect
Finished goroutines enter the dead state and are cleaned up by the runtime.
Which of these is a reason goroutines are lightweight?
✗ Incorrect
Goroutines use small stacks that grow as needed, making them lightweight compared to OS threads.
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.