Correct cyclesLate if an event consumes cycles.

This can prevent things from drifting out of sync.
Fix periodic events drifting when eating cycles.

Need to set the next timer before rescheduling threads or etc.
Add some missing algorithm includes.