Translating with DrWatson… this can take a few seconds the first time.
This is a genuine, complex translation. DrWatson protects commands, error codes, and log output while naturally translating the surrounding text. It’s translated once and saved.
SangGyu Jeong asked how to sleep for milliseconds in SPL on AIX, where system sleep and yieldn did not work. David Williams suggested a C UDR; Andreas Legner and Paul Watson warned it must yield (mi_yield) or the CPU VP is lost to the OS. Art Kagel offered a gettimeofday UDR; Paul posted a clock_nanosleep loop with mi_yield that worked on Linux.
Auto-generated by Claude from the posts below — may be imperfect; read the full thread.
SangGyu Jeong — source: IBM Community (ConnectedCommunity.org) Informix forum
Hello All,
Is there a function in SPL that works similar to sleep?
I used system ('sleep 5') , sysmaster:yieldn(), sysadmin:yieldn() functions, etc, but it doesn't seem to work in milisecond units. Because it is an AIX environment, usleep or nsleep cannot be used.
Any ideas?
drop procedure myproc;
create procedure myproc()
insert into tmp1 select dbinfo('utc_to_datetime',sh_curtime) from sysmaster:sysshmvals;select sysmaster:yieldn(0.01) y from sysmaster:sysdual into temp ifxtmp1 with no log;
insert into tmp1 select dbinfo('utc_to_datetime',sh_curtime) from sysmaster:sysshmvals;
drop table ifxtmp1;end procedure;
------------------------------
SangGyu Jeong
Software Engineer
Infrasoft
Seoul Korea, Republic of
------------------------------
#Informix
↪ replying to SangGyu Jeong
David Williams — source: IBM Community (ConnectedCommunity.org) Informix forum
Andreas Legner — source: IBM Community (ConnectedCommunity.org) Informix forum
Problem with this probably would be that, instead of yielding the Informix thread (to another one) while 'sleeping', you'd yield the cpu vp (to the OS).
------------------------------
Andreas Legner
------------------------------
↪ replying to David Williams
Paul Watson — source: IBM Community (ConnectedCommunity.org) Informix forum
Don't do that – your engine will not love you for it.
You need to do very small micro sleeps with lots of mi_yield otherwise you will probably lose the VP you are running in to the OS
Cheers
Paul
↪ replying to Andreas Legner
Art Kagel — source: IBM Community (ConnectedCommunity.org) Informix forum
I have a UDR that calls gettimeofday() to return microsecond resolution time. One could loop on that call until the desired sub-second time had elapsed.
> execute function adbm_gettimeofday();(expression)
2021-12-14 17:00:21.93423
1 row(s) retrieved.
If anyone is interested in the source, email me.
------------------------------
Art S. Kagel, President and Principal Consultant
ASK Database Management Corp.
www.askdbmgt.com
------------------------------
↪ replying to Art Kagel
Paul Watson — source: IBM Community (ConnectedCommunity.org) Informix forum
The high level logic in the UDR is
for(i=HowLongMS; i--;)
{
usleep(1)
Mi_yield()
}
You don't want to directly sleep for 25ms, the engine can do a lot in 25ms
J
You could look at nanosleep but I suspect that is not what you want.
Cheers
Paul
↪ replying to Paul Watson
Paul Watson — source: IBM Community (ConnectedCommunity.org) Informix forum
Been playing on my Linux, usleep (1) maps to nanosleep(0,1000) – live and learn
↪ replying to Paul Watson
Paul Watson — source: IBM Community (ConnectedCommunity.org) Informix forum
Appears to work under Linux
void oni_sleep(mi_integer ms)
{
struct timespec ts;
int i;
long next_tick;
clock_getres(CLOCK_MONOTONIC, &ts);
clock_gettime(CLOCK_MONOTONIC, &ts);
for(i=ms;i--;)
{
next_tick = (ts.tv_sec * 1000000000L + ts.tv_nsec) + 1000000;
ts.tv_sec = next_tick / 1000000000L;
ts.tv_nsec = next_tick % 1000000000L;
clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, NULL);
mi_yield();
}
}
We use strictly necessary cookies to make this site work. With your
consent we’d also use optional cookies for analytics and marketing. You can accept all,
reject all, or choose. Read our Cookie Policy.