Re: POSIX Timers on Linux 2.4
- From: Josh Birnbaum <engineer@xxxxxxxxx>
- Date: Mon, 23 Jan 2006 03:30:32 GMT
Kasper Dupont wrote:
Hi Kasper,
> Josh Birnbaum wrote:
> >
> > The code follows. Any feedback re the above is welcome.
>
> I have no experience with POSIX timers, but I did notice
> a few bugs in the way you handle signals.
>
> >
> > if( timer_settime( timerOne, 0, &spec, NULL ) != 0 )
> > {
> > perror( "timer: ERROR: timer_settime" );
> > exit( EXIT_FAILURE );
> > }
> >
> > if( sigaction( SIGINT, &sigAct, NULL ) != 0 )
> > {
> > perror( "timer: ERROR: sigaction" );
> > exit( EXIT_FAILURE );
> > }
>
> You should install the handler earlier. A signal handler
> need to be installed before you perform the action which
> will cause a signal to be send. Though it is highly
> unlikely, it is theoretically possible, that you are
> preempted just before the sigaction call and then don't
> get the CPU again before the signal fires.
Yes, I had thought about my placement of the sigaction() call
relative to timer_create() and timer_settime. I am now exper-
imenting with calling sigaction() earlier in my code.
> >
> > for( ;; )
> > {
> > intr = 0;
> >
> > pause();
> >
> > if( intr )
> > {
> > printf( "caught SIGINT\n" );
> > }
> > }
>
> There are multiple race conditions in this code.
Ah, thanks for this feedback. You're referring specifically to
signals race conditions?
Thanks,
Josh.
P.S. Apologies re the multi post. I had already posted by the time
I noticed it.
> --
> Kasper Dupont -- Rigtige mænd skriver deres egne backupprogrammer
> #define _(_)"d.%.4s%."_"2s" /* This is my new email address */
> char*_="@2kaspner"_()"%03"_("4s%.")"t\n";printf(_+11,_+6,_,6,_+2,_+7,_+6);
.
- Prev by Date: Re: SMP and Multithreaded Applications under linux
- Next by Date: Re: working with files the linux way...
- Previous by thread: fork question
- Next by thread: G++ Help
- Index(es):
Relevant Pages
|