This entire block shouldn't need to be unsafe, and I don't think any more `unsafe` blocks should be added to the scheduler at all. It would be nice to have a wrapper around the `AtomicBool` to hide the unsafety (because it's not actually unsafe).