Best way to get back in sync after a live_loop dies?

Suppose I have:

live_loop :loop1 do
  play 80
  sleep 0.5
end

live_loop :loop2 do
  play 40
  sleep 1
end

And then I accidentally do:

live_loop :loop1 do
  play 80
  sleep 0.5
end

live_loop :loop2 do
  play 40
  #sleep 1
end

so that loop2 dies. What’s the best way to re-start loop2 so that it starts in proper sync with loop1?

Using the sync: opt of live_loop makes this pretty easy.
If you want them to both be synced together from the beginning anyway, then it’s simple to add it like so: live_loop :loop2, sync: :loop1 do...
This will synchronise them once when :loop2 starts, and they will play on independently from then on.

Keep in mind that syncing threads/loops will only catch a cue that happens after they have started waiting. In the case of live_loop :loop2, sync: :loop1 do - since :loop1 and :loop2 are started at the same time, :loop2 waits for the next time :loop1 sends out its cue message to let the loop continue - meaning :loop2 will start playing sound 0.5 beats after :loop1, but synchronised in time with it.

(This has been discussed at length elsewhere in the forum if you want further information behind the syncing mechanism - see Live loops Sync questions :-) for details).

Yes, I’d searched around and had seen that other thread, but I couldn’t figure out this rather basic need: during live coding, if one loop dies, how do you restart it so that its restart coincides with all other loops’ restarts? I did get the synchronized-0.5-beats-later result that you describe, but that’s not what I mean by “back in sync,” which I’ll now call “in total sync.”

I actually don’t use sync at all, anywhere, ever. I’m just looking for a live performance trick to get things back in total sync after a live coding error.

ADDED: Wait, my toy example wasn’t representative of what I’m actually doing. For the stuff I’m working on, all function calls in a live loop sleep for a total of one beat. In that case, the resurrected loop would always start exactly one beat later. In this particular case, synchronization is all that matters to me as long as the resurrected loop is “late” by an integer number of beats. So editing in the sync: opt and reloading should always work (I think).