It turns out that we should add volatile before cur_ms to prevent it from being optimized out.