Skip to main content
Solved

Unidata 7.2 on AIX - Is there a way to do a millisecond sleep?

  • April 20, 2021
  • 15 replies
  • 2 views

Kevin King
I have a need to do a 400ms sleep in a Unidata program.  Is it possible?

Best answer by Steve Wingfield

I have a need to do a 400ms sleep in a Unidata program.  Is it possible?
Hi Kevin,

You could also leverage openSocket's millisecond timeout parameter, and go to a non-listening address:


DESIRED.SLEEP.TIME = 400 ;* in milliseconds

* openSocket tries 3 times, so scale down
* the desired sleep time by 1/3...
SOCKET.TIMEOUT     = INT(DESIRED.SLEEP.TIME/3)
NON.LISTENING.IP   = "192.0.2.0" ; * see https://tools.ietf.org/html/rfc5737
NON.LISTENING.PORT = 0
BLOCKING           = 1
START.TIME = SYSTEM(12)
RET = openSocket(NON.LISTENING.IP, NON.LISTENING.PORT, BLOCKING, SOCKET.TIMEOUT, OUT.HANDLE)
END.TIME = SYSTEM(12)

PRINT "Elapsed Time: " : (END.TIME - START.TIME)
​

15 replies

David Green
  • Inspiring
  • 48 replies
  • April 20, 2021
I have a need to do a 400ms sleep in a Unidata program.  Is it possible?
Try using SYSTEM(12)

David Green
  • Inspiring
  • 48 replies
  • April 20, 2021
I have a need to do a 400ms sleep in a Unidata program.  Is it possible?
or maybe you could shell out and do a Unix sleep 0.4 with PCPERFORM?

Kevin King
  • Author
  • Participating Frequently
  • 53 replies
  • April 20, 2021
I have a need to do a 400ms sleep in a Unidata program.  Is it possible?
the problem with SYSTEM(12) is that to use this would require a tight loop and that's exactly what I'm trying to avoid.  Regarding shelling out, thought about that too but it's impossible to calculate the ms overhead of the shell execution to more precisely hit the delay time.

David Green
  • Inspiring
  • 48 replies
  • April 20, 2021
I have a need to do a 400ms sleep in a Unidata program.  Is it possible?
That's all true.  I believe the only method left is to use CALLC.

Kevin King
  • Author
  • Participating Frequently
  • 53 replies
  • April 20, 2021
I have a need to do a 400ms sleep in a Unidata program.  Is it possible?
yeah, I was afraid of that.  No way I want to try to do a CALLC thing on an AIX box.

  • 0 replies
  • April 20, 2021
I have a need to do a 400ms sleep in a Unidata program.  Is it possible?
Can PAUSE accept a fraction?
If it was a later system then, callout to Python...
pytime = pyImport('time')
z  = pyCallMethod(pytime,'sleep',0.4)

Nik Kesic001
Forum|alt.badge.img+1
  • Participating Frequently
  • 29 replies
  • April 21, 2021
I have a need to do a 400ms sleep in a Unidata program.  Is it possible?
Hello Kevin

the AIX freeware tools have a updated version of sleep. You can sleep milliseconds

AE BP WAIT
Top of "WAIT" in "BP", 4 lines, 90 characters.
001: CRT "START"
002: PCPERFORM "timex /opt/freeware/bin/sleep 0.5" CAPTURING NED
003: CRT NED
004: CRT "DONE"
Bottom.
*--: fibr
Filed "WAIT" in file "BP".

Compiling Unibasic: BP/WAIT in mode 'u'.
compilation finished
START
þreal 0.50þuser 0.00þsys 0.00þþ
DONE


Nik

Nik Kesic001
Forum|alt.badge.img+1
  • Participating Frequently
  • 29 replies
  • April 21, 2021
I have a need to do a 400ms sleep in a Unidata program.  Is it possible?
Kevin,

You could do this
  sleep 0.001

And you can install the package "yum install AIX_Toolbox" if you don't have it.

Nik

Kevin King
  • Author
  • Participating Frequently
  • 53 replies
  • April 21, 2021
I have a need to do a 400ms sleep in a Unidata program.  Is it possible?
That's great Nik, thanks.  What's the overhead of the PCPERFORM?  Any way to get a timing on that?

Nik Kesic001
Forum|alt.badge.img+1
  • Participating Frequently
  • 29 replies
  • April 21, 2021
I have a need to do a 400ms sleep in a Unidata program.  Is it possible?
Hello Kevin

My gut feel tells me microseconds... or maybe worst case 10 mS.

I was trying to figure a good truss command to see how much... I will look deeper and see if I can find something

cheers

Nik

David Green
  • Inspiring
  • 48 replies
  • April 21, 2021
I have a need to do a 400ms sleep in a Unidata program.  Is it possible?
can you time like this:

START.TIME = SYSTEM(12)
PCPERFORM "echo Testing" CAPTURING BUFF
END.TIME = SYSTEM(12)
DURATION = END.TIME - START.TIME
PRINT DURATION
*
** Since PCPERFORM overhead and execution may vary from moment to moment do this:
*
Then take your 400 milliseconds - (Duration * 2) to come up with the sleep time you need.

Kevin King
  • Author
  • Participating Frequently
  • 53 replies
  • April 21, 2021
I have a need to do a 400ms sleep in a Unidata program.  Is it possible?
That is SUPER clever David.  Good on ya, man.  

It does make an assumption that the overhead is going to be constant, but then again even if the timer were baked into Unidata, there would be some variability based on load.  But dang, a great idea!

Nik Kesic001
Forum|alt.badge.img+1
  • Participating Frequently
  • 29 replies
  • April 21, 2021
I have a need to do a 400ms sleep in a Unidata program.  Is it possible?
Hi Kevin

I used system(12) as suggested by @David Green and it looks like the cost is 6-8mS 

​STIME=SYSTEM(12)
PCPERFORM "/opt/freeware/bin/sleep 0.5" CAPTURING NED
ETIME=SYSTEM(12)
TTIME=ETIME-STIME
CRT TTIME

My test ran on a IBM Power 924 
On a P980 with 4K users, the times were 10-15mS scewed

Nik

Steve Wingfield
  • Rocketeer
  • 18 replies
  • Answer
  • April 22, 2021
I have a need to do a 400ms sleep in a Unidata program.  Is it possible?
Hi Kevin,

You could also leverage openSocket's millisecond timeout parameter, and go to a non-listening address:


DESIRED.SLEEP.TIME = 400 ;* in milliseconds

* openSocket tries 3 times, so scale down
* the desired sleep time by 1/3...
SOCKET.TIMEOUT     = INT(DESIRED.SLEEP.TIME/3)
NON.LISTENING.IP   = "192.0.2.0" ; * see https://tools.ietf.org/html/rfc5737
NON.LISTENING.PORT = 0
BLOCKING           = 1
START.TIME = SYSTEM(12)
RET = openSocket(NON.LISTENING.IP, NON.LISTENING.PORT, BLOCKING, SOCKET.TIMEOUT, OUT.HANDLE)
END.TIME = SYSTEM(12)

PRINT "Elapsed Time: " : (END.TIME - START.TIME)
​

Kevin King
  • Author
  • Participating Frequently
  • 53 replies
  • April 22, 2021
I have a need to do a 400ms sleep in a Unidata program.  Is it possible?
Wow, that is a great idea.  Thank you sir!