views:

33

answers:

1

A valuable answer will include the rpg code that does something like this

volatile bool interrupted;
main() {
  sigaction(SIG_ALARM, myhandler) // register handler
  alarm(3) // set the alarm
  sleep(5) // blocking call, sleep just as an example.
  alarm(0) // disable the alarm
}
myHandler() {
  interrupted=true
}

I think you've got the idea. I have a code that blocks, similar to sleep, and I want an alarm to unlock the blocking call

Another question, after the alarm handler has finished, where does the execution point goes ? does it terminate the program ?, can I call another method while inside myHandler() ? Is it allowed, how can I keep doing something before the program finishes, like log to a table till where did I went ?

Thank you very much !

+1  A: 

This article gives some good examples of using signals (including SIG_ALARM) from ILE RPG: http://systeminetwork.com/article/terminate-and-stay-residentin-rpg

If your program is running while SIG_ALARM is received, execution temporarily switches to the alarm handler. After the alarm handler is finished, execution resumes where it left off.

The example given in the link does QCMDEXC and file IO from the alarm handler, so it would seem like you can do just about anything there. (Though, his example had basically no mainline running that could be interfered with; in fact his alarm handler was running after the mainline ended!)

dmc