linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Race: SignalHandler() & sleep()
@ 2002-06-04 14:48 Hossein Mobahi
  2002-06-04 22:24 ` george anzinger
  0 siblings, 1 reply; 2+ messages in thread
From: Hossein Mobahi @ 2002-06-04 14:48 UTC (permalink / raw)
  To: linux-c-programming; +Cc: linux-kernel

Hello

main()
{
    ....
    signal (SIGIO, signalhandler() ) ;
    ....
    sleep (65535) ;
    ....
}

signalhandler() { ... } 

Assume the frequency of IO events is faster than one
event per 65535 seconds. Therefore, let's consider
65535 as infinity (sleeping foreveR).
If a SIGIO arrives, main will get out of sleep and
continue running, but signalhandler will be invoked
too. I wanted to know if there is any order/priority
for sleep() in main, and signalhandler() to be called
first, or one of them is invoked first randomly (race
condition) ?

I myself ran the program many times and everytime
observed signalhandler responding first. But maybe it
is not a rule, and it was just my chance ?

Thnx for your comment !

--Hossein Mobahi


__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Race: SignalHandler() & sleep()
  2002-06-04 14:48 Race: SignalHandler() & sleep() Hossein Mobahi
@ 2002-06-04 22:24 ` george anzinger
  0 siblings, 0 replies; 2+ messages in thread
From: george anzinger @ 2002-06-04 22:24 UTC (permalink / raw)
  To: Hossein Mobahi; +Cc: linux-c-programming, linux-kernel

Hossein Mobahi wrote:
> 
> Hello
> 
> main()
> {
>     ....
>     signal (SIGIO, signalhandler() ) ;
>     ....
>     sleep (65535) ;
>     ....
> }
> 
> signalhandler() { ... }
> 
> Assume the frequency of IO events is faster than one
> event per 65535 seconds. Therefore, let's consider
> 65535 as infinity (sleeping foreveR).
> If a SIGIO arrives, main will get out of sleep and
> continue running, but signalhandler will be invoked
> too. I wanted to know if there is any order/priority
> for sleep() in main, and signalhandler() to be called
> first, or one of them is invoked first randomly (race
> condition) ?
> 
> I myself ran the program many times and everytime
> observed signalhandler responding first. But maybe it
> is not a rule, and it was just my chance ?
> 
In linux (and most (all) unices) pending signals are checked
for on exit from the kernel so the order of operation is:

wake up (end of sleep) still in kernel
on exit from kernel, find signal, and deliver it, i.e. call
handler if there is one
on return from the handler, continue with the exit from the
system.

-- 
George Anzinger   george@mvista.com
High-res-timers: 
http://sourceforge.net/projects/high-res-timers/
Real time sched:  http://sourceforge.net/projects/rtsched/
Preemption patch:
http://www.kernel.org/pub/linux/kernel/people/rml

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-06-04 22:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-06-04 14:48 Race: SignalHandler() & sleep() Hossein Mobahi
2002-06-04 22:24 ` george anzinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).