With spinlocks like this there are usually more elegant solutions (using notifications, or "concurrent.futures" type threading or such), but I don't think I have the whole context so this is fine for now.