[949] in java-interest
Setting up a signal handler
daemon@ATHENA.MIT.EDU (Louis Theran)
Tue Aug 15 20:36:26 1995
From: Louis Theran <louis@osf.org>
Date: Tue, 15 Aug 1995 17:27:49 -0400
To: java-interest@java.sun.com
I am trying to set up a mechanism that will work in the same way that
the following works in C:
void
wake_me(void(*)() func,int duration) {
signal(SIGALRM,func);
alarm(duration);
}
That is wait duration seconds and then execute func, letting the
program continue running during the wait.
I have tried using threads, but there is no way to tell if one is
sleeping (as far as I can tell), so that isn't a good timing
mechanism here if it is just used as a condition for a while loop
or something like that. My knowlege of setting and changing
thread priorities is not very in depth, but I was unable to get
the desired effect by putting the function call in a thread and
then putting it to sleep. If this can I done, I would greatly
appreciate it if you would explain how.
As a last measure, I tried writing native methods that call signal
itself, but that doesn't work because all native methods have to
have at least 1 argument (a Handle*) in order to have any effect
on the calling java object/program; signal doesn't take functions
with arguments, so the runtime system's response is to pass
a bunch of impossible addresses, which causes it (the interpreter) to
barf.
The purpose of this whole thing is to translate a C program into java
for purposes of comparison, so while I know that I could use some
other method of timing (i.e. doing a fixed number of calls and seeing
how long that takes), it would be a much better comparison if I could
use the same mechanism in both programs.
Thanks,
Louis Theran
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com