[ECOS] POSIX timer callback context
Wed Oct 29 17:04:00 GMT 2003
Okay, I see what you're saying. I had to dig into
this a little more to realize that the eCos POSIX
implementation really treats the whole system as one
single process, with each task just being its own
thread within that process. So in effect, signal
handling is shared amoung all "tasks" in the system.
However, it seems to me that timer signals would be
more useful if an attempt was made to deliver them
back to the thread that set the timer. Consider the
scenario where you have N instances of the same task
running in parallel, each wanting to be woken up by
their own independent timers.
POSIX has this to say about signal delivery:
At the time of generation, a determination shall be
made whether the signal has been generated for the
process or for a specific thread within the process.
Signals which are generated by some action
attributable to a particular thread, such as a
hardware fault, shall be generated for the thread that
caused the signal to be generated. Signals that are
generated in association with a process ID or process
group ID or an asynchronous event, such as terminal
activity, shall be generated for the process.
It seems like an argument could be made that setting a
timer is an "action attributable to a particular
thread". Last night I enhanced the POSIX timer code
to record the thread that called timer_settime() in
the timer object. Then, when the timer goes off, it
tries to deliver the signal to that thread first. The
changes were fairly minor and they seemed to do what I
So my question for you is: do you think this is a
reasonable way to handle timer signal delivery? Do
you see any problems with this?
I've attached a diff of my (pending) changes for your
reference if you're interested.
--- Nick Garnett <firstname.lastname@example.org> wrote:
> Dan Jakubiec <email@example.com> writes:
> > I'm using a POSIX timer in my application that I
> > created with timer_create(). It is configured to
> > generate a SIGUSR1 signal when the timer expires,
> > to call a signal handler installed by my app's
> > I also have several different tasks running that
> > all created with pthread_create().
> > When the timer expires, the signal handler gets
> > executed, but it appears to be executing in a
> > thread's context (i.e. pthread_self() returns the
> > handle for one of my other threads). Furthermore,
> > thread that installed the handler is waiting in a
> > pselect() call that never gets interrupted with
> > This seems like a bug to me, but I wanted to pass
> > by the group before fixing it to make sure I
> > missing anything. Seems like there is a bit of a
> > area in the POSIX docs about whether signals get
> > delivered to the "process" or one of its
> > However, it seems that in eCos it would only make
> > sense to deliver signals to the calling thread
> > Does anyone have any background info on the eCos
> > implementation of POSIX timers, or an opinion on
> > POSIX timer callbacks should be processed?
> This is not a bug. The POSIX spec is fairly clear
> that these are
> process-wide signals that will be delivered to any
> thread that has the
> signal unmasked. There are lots of problems with
> doing thread-specific
> signals here that the POSIX committee decided to
> avoid by
> side-stepping the problem.
> If you want to direct the signal to a specific
> thread then just make
> sure that that thread is the only one with the
> signal unmasked. The
> best way to ensure this is to mask it in the signal
> mask of main()
> before creating any other threads, which will then
> inherit main()'s
> mask, and unmask it in the target thread.
> Nick Garnett eCos Kernel
> http://www.ecoscentric.com The eCos and RedBoot
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 2437 bytes
-------------- next part --------------
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss
More information about the Ecos-discuss