Bird
0
0

How can you use Fibers to implement a simple cooperative task scheduler that switches between two tasks?

hard📝 Application Q8 of 15
Ruby - Concurrent Programming
How can you use Fibers to implement a simple cooperative task scheduler that switches between two tasks?
ARun tasks sequentially without yielding
BCreate two Fibers that yield control to each other alternately
CUse two threads and join them
DUse a loop that calls Fiber.yield outside Fiber blocks
Step-by-Step Solution
Solution:
  1. Step 1: Understand cooperative scheduling with Fibers

    Fibers can pause and resume, so two Fibers can yield control to each other to simulate multitasking.
  2. Step 2: Evaluate options

    Only Create two Fibers that yield control to each other alternately correctly describes creating two Fibers that yield control alternately. Others describe unrelated or incorrect approaches.
  3. Final Answer:

    Create two Fibers that yield control to each other alternately -> Option B
  4. Quick Check:

    Cooperative scheduling = Fibers yield control alternately [OK]
Quick Trick: Use Fibers yielding to each other for cooperative multitasking [OK]
Common Mistakes:
  • Confusing Fibers with threads
  • Trying to yield outside Fiber blocks
  • Running tasks sequentially without yielding

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes