A Not-Quite-As-Sleepy RPG Program
May 13, 2009 Hey, Ted
Thanks for the information about the sleep API. On a recent project, we had a requirement to ensure that two operations were at least a microsecond apart, but a full second proved to be far too long. (Seconds add up quickly!) We created a DLYJOBSML (Delay Job for Small Duration) command and invoked the usleep API in the CPP.
Like sleep, usleep also delays a job. The difference is that the usleep parameter denotes milliseconds, rather than whole seconds. You might say that sleep is like going to bed at night, whereas usleep only takes a nap.
Here’s the code from the previous article retrofitted with usleep.
H dftactgrp(*no) actgrp(*new) H option(*srcstmt:*nodebugio) H bnddir('QC2LE') D usleep pr 10u 0 extproc('usleep') D Interval 10u 0 value D t1 s z D t2 s z /free *inlr = *on; t1 = %timestamp(); usleep (150); t2 = %timestamp(); return;
Like sleep, usleep does not cause an exact delay. That is, just because you ask for 150 milliseconds doesn’t mean you’re going to get it. You’ll probably get more or less.
Blair was not the only one to write in about usleep. Thanks to everyone who took the time to write.