home/ atoms/ chuck-shred-lifecycle

Sporked ChucK shreds die when their parent shred ends

When a parent shred in ChucK reaches its end, every shred it spawned with spork is killed immediately. So if main exits, all the music stops even though child shreds were mid-loop. The standard pattern is to keep the parent alive with an infinite time-advancing loop: while(true) 1::second => now;. Without it, a program that sporks its voices and then falls off the end produces at most a click before everything is torn down.

Examples

spork ~ playMelody(); // child shred // if main reaches here, playMelody shred is killed while(true) 1::second => now; // keep parent alive

Assessment

Describe what happens when a ChucK program ends its main with spork ~ voice() still running, and write the one-line fix that keeps the music playing indefinitely.

“Sporked children die with the parent.** If `main` reaches its end, all shreds it sporked are killed. Keep the parent alive (`while(true) 1::second => now;`) or the music stops instantly.”
context/ · L1-instruments/chuck/gotchas.md · chunk 1