Recall & Review
beginner
What is a thread in Ruby?
A thread is a lightweight unit of execution within a Ruby program that allows multiple tasks to run at the same time.
Click to reveal answer
beginner
How do you create a new thread in Ruby?
Use
Thread.new { ... } to create and start a new thread that runs the code inside the block.Click to reveal answer
beginner
What does
thread.join do in Ruby?It makes the main program wait until the thread finishes its work before continuing.
Click to reveal answer
intermediate
Can Ruby threads run truly in parallel?
MRI Ruby threads are native threads and run concurrently but not truly in parallel because of the Global Interpreter Lock (GIL).
Click to reveal answer
intermediate
What happens if you don't join a thread in Ruby?
The main program may finish before the thread completes, causing the thread to be killed prematurely.
Click to reveal answer
How do you start a new thread in Ruby?
✗ Incorrect
In Ruby,
Thread.new { ... } creates and starts a new thread running the code inside the block.What method waits for a thread to finish before continuing?
✗ Incorrect
join() pauses the main thread until the called thread completes.Which Ruby implementation has a Global Interpreter Lock (GIL) affecting threads?
✗ Incorrect
MRI Ruby uses a GIL, so threads run concurrently but not in true parallel.
What happens if the main program ends before a thread finishes?
✗ Incorrect
If the main program ends, any running threads are killed immediately.
Which of these is a correct way to create and run a thread that prints 'Hello'?
✗ Incorrect
Thread.new { puts 'Hello' } creates and runs a thread that prints 'Hello'.Explain how to create and execute a thread in Ruby and why you might want to use
join.Think about starting a task in the background and waiting for it to finish.
You got /4 concepts.
Describe the effect of the Global Interpreter Lock (GIL) on Ruby threads and how it impacts parallel execution.
Consider how threads share the CPU in MRI Ruby.
You got /4 concepts.