Custom defined object in a signal handler
I have a question regarding signals. Is there a way you can pass some custom defined parameter (say, a struct foo * ) to a signal handler??
To be more specific, struct sigaction defines 2 types of handlers - namely sa_handler and sa_sigaction both of which have predefined set of arguments to them.
sa_handler has (int) as the argument and sa_sigaction has (int, siginfo_t *, void *) as its arguments. The third argument void * to sa_sigaction is for a ucontext_t struct that contains the process's context at the time of signal delivery.
My requirement is: I need to pass a struct foo * pointer to the signal handler when I set it up and later when the signal is delivered I must be able to see the foo * that I had passed at the time of setting up the handler. Does anyone know how we can do this?
TIA,
Sreevathsa
Quoted 2 lines · Sreevathsa
I have a question regarding signals. Is there a way you can pass some custom defined parameter (say, a struct foo * ) to a signal handler??
No (other than by using a global variable).
As you can only install a single handler for any given signal, there isn't any real need to support closures.
Signature · 1 line
Glynn Clements <[email protected]>
I am working on a multithreaded application in which, in one of the code paths, multiple threads need to setup a SIGALRM signal (to achieve TCP retrasmission kind of functionality). When each thread does this, it also need to pass the address of the structure that it operated upon, so that when the signal is delivered, the signal handling thread will know the address of the strucutre and can act upon it.
Is there any way to accomplish this goal? If you need any other info about the problem environment, I can provide them, please let me know.
Thanks,
Sreevathsa
Quoted 29 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Glynn Clements
Sent: Wednesday, March 28, 2007 5:09 PM
To: Sreevathsa
Cc: [email protected]
Subject: Re: Custom defined object in a signal handlerQuoted 1 line · Sreevathsa
I have a question regarding signals. Is there a way you can
pass some
Quoted 1 line
custom defined parameter (say, a struct foo * ) to a signal
handler??
No (other than by using a global variable).
As you can only install a single handler for any given signal, there isn't any real need to support closures.
--
Glynn Clements <[email protected]>
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected] More majordomo info at
http://vger.kernel.org/majordomo-info.html
Quoted 6 lines · Sreevathsa
I am working on a multithreaded application in which, in one of the code paths, multiple threads need to setup a SIGALRM signal (to achieve TCP retrasmission kind of functionality). When each thread does this, it also need to pass the address of the structure that it operated upon, so that when the signal is delivered, the signal handling thread will know the address of the strucutre and can act upon it.
Signal handlers are per-process, not per-thread; only the mask is per-thread. Likewise for timers.
Signature · 1 line
Glynn Clements <[email protected]>