Skip to content

Commit 56ed7c8

Browse files
committed
document sleep
1 parent 122fbc6 commit 56ed7c8

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

doc/specs/stdlib_system.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,3 +315,35 @@ else
315315
print *, "Failed to kill the process."
316316
end if
317317
```
318+
319+
## `sleep` - Pause execution for a specified time in milliseconds
320+
321+
### Status
322+
323+
Experimental
324+
325+
### Description
326+
327+
The `sleep` interface pauses the execution of a program for a specified duration, given in milliseconds.
328+
This routine acts as a cross-platform wrapper, abstracting the underlying platform-specific sleep implementations.
329+
It ensures that the requested sleep duration is honored on both Windows and Unix-like systems.
330+
331+
### Syntax
332+
333+
`call ` [[stdlib_system(module):sleep(subroutine)]] `(millisec)`
334+
335+
### Arguments
336+
337+
`millisec`: Shall be an `integer` representing the number of milliseconds to sleep. This is an `intent(in)` argument.
338+
339+
### Example
340+
341+
```fortran
342+
! Example usage of sleep
343+
print *, "Starting sleep..."
344+
345+
! Sleep for 500 milliseconds
346+
call sleep(500)
347+
348+
print *, "Finished sleeping!"
349+
```

src/stdlib_system.F90

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,14 +256,31 @@ module subroutine process_kill(process, success)
256256
end subroutine process_kill
257257
end interface kill
258258

259-
260-
!! version: experimental
261-
!!
262259
interface sleep
260+
!! version: experimental
261+
!!
262+
!! Pauses execution for a specified time in milliseconds.
263+
!! ([Specification](../page/specs/stdlib_system.html#sleep-pause-execution-for-a-specified-time))
264+
!!
265+
!! ### Summary
266+
!! Pauses code execution for a specified number of milliseconds. This routine is a cross-platform
267+
!! wrapper around platform-specific sleep functions, providing consistent behavior on different operating systems.
268+
!!
269+
!! ### Description
270+
!!
271+
!! This interface allows the user to pause the execution of a program for a specified duration, expressed in
272+
!! milliseconds. It provides a cross-platform wrapper around native sleep functions, ensuring that the program
273+
!! will sleep for the requested amount of time on different systems (e.g., using `Sleep` on Windows or `nanosleep`
274+
!! on Unix-like systems).
275+
!!
276+
!! @note The precision of the sleep may vary depending on the system and platform.
277+
!!
263278
module subroutine sleep(millisec)
279+
!> The number of milliseconds to pause execution for.
264280
integer, intent(in) :: millisec
265281
end subroutine sleep
266-
end interface sleep
282+
end interface sleep
283+
267284

268285
!! version: experimental
269286
!!

0 commit comments

Comments
 (0)