The following code causes the interpreter to freeze and become permanently unresponsive on my machine.
(
Routine({
loop {
var x;
x = 3;
10000.do { x = x.cos; };
0.0001.wait;
};
}).play;
)
The behavior is dependent on the wait time and the number of iterations. For example, with 1000.do or with 0.001.wait it is fine. With 100000.do it’s an immediate crash with a message saying grey count error, and the lowest order of magnitude wait time that doesn’t freeze or crash is 0.1s. So it is not just short waits, but a combination of short waits and expensive operations. You might need to adjust the numbers to repro on your machine, as I suspect this is a race condition.
Is there any workaround to this? I could empirically test what the minimum safe wait time is in seconds and use a bandage like max(1e-3 * thisThread.clock.tempo, intendedWaitInBeats).wait, but then the timing of the Routine will become musically inaccurate, and it’s still not a guarantee against a freeze. (Attempting to work around that by forking at each expensive operation is also a no-go, because then I get errors about the scheduler queue being full.)
EDIT: I have reproduced this issue in 3.13 on Linux. Originally found the issue on my client’s machine, 3.12 on macOS. The code I wrote for him worked fine in testing, and had safeguards against very short waits, but as he started using the software at a larger scale, the inter-wait operations became slower and his live setup started freezing at high tempos.