Busy-wait for approximately s seconds.
This implementation uses system_clock to measure elapsed ticks.
It does not yield to the OS scheduler and may consume CPU while waiting.
s: requested duration in seconds. Non-positive values return immediately.| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real, | intent(in) | :: | s |
subroutine sleep_spin(s) real, intent(in) :: s integer(int64) :: rate, t0, t1, ticks if (s <= 0.0) return call system_clock(count_rate=rate) if (rate <= 0_int64) rate = 1000_int64 ticks = int(s * real(rate), int64) if (ticks <= 0_int64) return call system_clock(t0) do call system_clock(t1) if (t1 - t0 >= ticks) exit end do end subroutine sleep_spin