Logo

Programming-Idioms

History of Idiom 45 > diff from v47 to v48

Edit summary for version 48 by jupiter:
New Fortran implementation by user [jupiter]

Version 47

2019-09-26, 15:37:50

Version 48

2019-09-27, 00:19:18

Idiom #45 Pause execution for 5 seconds

Sleep for 5 seconds in current thread, before proceeding with next instructions.

Illustration

Idiom #45 Pause execution for 5 seconds

Sleep for 5 seconds in current thread, before proceeding with next instructions.

Illustration
Code
module M_time
contains
subroutine system_sleep(wait)
use,intrinsic       :: iso_c_binding, only: c_int
integer,intent(in)  :: wait
integer(kind=c_int) :: waited
interface
   function c_usleep(msecs) bind (C,name="usleep")
      import
      integer(c_int) :: c_usleep
      integer(c_int), intent(in), VALUE :: msecs
   end function c_usleep
end interface
   if(wait.gt.0)then
      waited=c_usleep(int(wait,kind=c_int))
   endif
end subroutine system_sleep
end module M_time
program demo_M_time
   u
Comments bubble
Fortran does not have an intrinsic to pause for a specified time period, but it is relatively easy to create an interface to a POSIX C routine