home/ atoms/ concurrency-sequential-loops-fail

Two infinite loops written in sequence can never both run, because the first loops forever and the second is never reached

A classic beginner surprise in Sonic Pi (and any single-threaded language) is writing two loops one after another and expecting both to sound. They cannot: the program runs top to bottom, reaches the first loop, and that loop runs forever — so control never reaches the second loop below it. This is not a bug but a fundamental property of single-threaded execution. To make both play, you need concurrency: two programs running simultaneously, one per loop. The hard part of concurrency is managing shared mutable state; if you avoid that, concurrency itself is not hard — which is what makes it teachable to children once the tool provides the right abstraction. Recognizing why the sequential version fails is the conceptual prerequisite to the live_loop solution.

Examples

A student writes loop {play drums} then loop {play bass}; only the drums sound, because the drums loop never ends and the bass loop below is never reached.

Assessment

Explain, in terms of single-threaded execution, why two loop do...end blocks in sequence can never both play. What is needed to make both run at once?

“it's not concurrent the program gets into the top of the it's a single threaded application so we get to the top we run the first Loop”
corpus · sam-aaron-sonic-pi-how-to-live-code-an-orchestra-goto-2023 · chunk 2