Block SIGALRM for a thread, not the main process..

Block SIGALRM for a thread, not the main process..

Post by Gaurav Navlakh » Wed, 21 Mar 2001 13:49:33



Hi,

I am creating a thread from my main. I need to handle signals
separately for each of them: ie., the thread and the main process. I read
it is possible, but can't figure out how.

The exact problem is that I'm using select() in the thread solely for the
purpose of a periodic timer. Select() generates the SIGALRM signal when
the timer expires. So what ends up happening is that my main process'
SIGALRM handler takes over and the entire process comes to a grinding
halt! I wish this select-> generated SIGALRM to not affect the main
process. Can I do it?

Any help will be appreciated.

Thanks,
Gaurav.

 
 
 

Block SIGALRM for a thread, not the main process..

Post by Arthur H. Gol » Wed, 21 Mar 2001 14:12:24



> Hi,

> I am creating a thread from my main. I need to handle signals
> separately for each of them: ie., the thread and the main process. I read
> it is possible, but can't figure out how.

> The exact problem is that I'm using select() in the thread solely for the
> purpose of a periodic timer. Select() generates the SIGALRM signal when
> the timer expires. So what ends up happening is that my main process'
> SIGALRM handler takes over and the entire process comes to a grinding
> halt! I wish this select-> generated SIGALRM to not affect the main
> process. Can I do it?

Use `pthread_sigmask()' to block SIGALRM in the main thread
(assuming you're on a truly POSIX-compliant platform, i.e.
not linuxthreads) -- POSIX specifies that a signal is
delivered to any threade that does not have the signal
blocked.
Under linuxthreads, the situation is somewhat different (as
threads are cloned processes). In that case, have the
`other' thread wait on a condition variable that you
pthread_cond_signal() when the select times out.

HTH,
--ag
--
Artie Gold, Austin, TX  (finger the cs.utexas.edu account
for more info)

--
Clone Bernie!