Waiting for ticks in thread instead of sleeping