Sleep: Difference between revisions

1,035 bytes added ,  9 months ago
→‎{{header|COBOL}}: added CONTINUE AFTER from COBOL 2023
No edit summary
imported>Acediast
(→‎{{header|COBOL}}: added CONTINUE AFTER from COBOL 2023)
Line 898:
 
=={{header|COBOL}}==
COBOL 2023 introduced the <code>AFTER</code> phrase of the <code>CONTINUE</code> statement to specify a time period in seconds for which execution will be suspended, which.
There are two methods for putting the program to sleep, both requiring unofficial extensions.
{{works with|GnuCOBOL}}
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. Sleep-In-Seconds.
 
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Seconds-To-Sleep USAGE IS FLOAT-LONG.
 
PROCEDURE DIVISION.
ACCEPT Seconds-To-Sleep
DISPLAY "Sleeping..."
CONTINUE AFTER Seconds-To-Sleep SECONDS
GOBACKDISPLAY "Awake!"
GOBACK.
 
END PROGRAM Sleep-In-Seconds.</syntaxhighlight>
 
TherePrior areto this there were two methods for putting the program to sleep, both requiringusing unofficial extensions.
 
The first expects the amount of time to be in seconds.
{{works with|ACUCOBOL-GT}}
{{works with|OpenCOBOLGnuCOBOL}}
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. Sleep-In-Seconds.
Line 907 ⟶ 926:
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Seconds-To-Sleep USAGE IS COMP-2.
*> Note: COMP-2, while supported on most implementations, is
*> non-standard. FLOAT-SHORT is the proper USAGE for Native
*> IEEE 754 Binary64 Floating-point data items.
 
PROCEDURE DIVISION.
ACCEPT Seconds-To-Sleep
 
DISPLAY "Sleeping..."
 
CALL "C$SLEEP" USING BY CONTENT Seconds-To-Sleep
 
DISPLAY "Awake!"
GOBACK.
 
END PROGRAM Sleep-In-Seconds.</syntaxhighlight>
GOBACK
.</syntaxhighlight>
 
While the second expects the time to be in nanoseconds. Note: Windows systems can only sleep to the nearest millisecond.
{{works with|OpenCOBOLGnuCOBOL}}
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. Sleep-In-Nanoseconds.
OPTIONS.
DEFAULT ROUNDED MODE IS NEAREST-AWAY-FROM-ZERO.
 
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Seconds-To-Sleep USAGE COMPIS FLOAT-2LONG.
01 Nanoseconds-To-Sleep USAGE COMPIS FLOAT-2LONG.
01 Nanoseconds-Per-Second CONSTANT AS 1000000000.
 
PROCEDURE DIVISION.
ACCEPT Seconds-To-Sleep
MULTIPLYCOMPUTE SecondsNanoseconds-To-Sleep BY Nanoseconds-Per-Second
GIVING= NanosecondsSeconds-To-Sleep * Nanoseconds-Per-Second
END-COMPUTE
 
DISPLAY "Sleeping..."
 
CALL "CBL_OC_NANOSLEEP"
USING BY CONTENT Nanoseconds-To-Sleep
END-CALL
 
DISPLAY "Awake!"
GOBACK.
 
END PROGRAM Sleep-In-Nanoseconds.</syntaxhighlight>
GOBACK
.</syntaxhighlight>
 
=={{header|Common Lisp}}==
Anonymous user