[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nptl] Re: nptl



> Hi,
>    Seb can u explain more about the NPTL's signal behavior in
> multi-threading aspect specially 


There are three important concept to understand when dealing with
signals:
- signal generation
- signal masks
- signal delivery and handling


1/ A signal can be generated in different ways. This can be user request
(with kill(), pthread_kill(), alarm(), ...) or hardware triggered
(segmentation fault,...). The signal can be generated for a process or
for a particular thread inside a process. This depend mostly on how the
signal was generated (hardware generated signals are often for a
process; user requests depends on how it was generated).


2/ For each thread of a process, there is a specific signal mask. The
signal mask is inherited from the parent when you call pthread_create,
but can be modified with pthread_sigmask. The signal mask specifies for
the thread which signals can be delivered to this thread, and which
should be blocked.

3/ When a signal has been generated for a thread, the signal mask for
this thread is examined. If the signal is blocked, then it remains
pending until a change in the signal mask, or a call to a specific
function (sigpending for example). If the signal is not blocked, then
the handler for this signal is examined. This handler is either the
signal is discarded; or the default handler (depends on each signal); or
else a user-defined function (registered with sigaction for example).
Note that this handler is unique for the whole process: you cannot have
a different handler from a thread to another.
When the signal has been generated for a process, then the signal masks
for all the threads inside this process are examined. If no thread does
not block the signal, it remains pending. If only one thread does not
block the signal, it is delivered to this thread. If several threads
does not block the signal, it is delivered to a random one of these.


Hope this helps.


> 
> One more problem I have receive one post from
> davide.rossetti@roma1.infn.it which says
> NPTL:
> - pthread_kill() is the only way to deliver a signal to a given thread, 
> but you have to have a pthread_t object.

true.

> - signal() delivers a signal to an "undefined" thread in the process (a 
> process is a group of threads in NPTL and in Posix Pthreads).

true.

> - there is no way to send a signal to one a particular thread in a 
> process (remember, a process _is_ a thread group) from outside that 
> group, because you have no pthread_t object to pass to pthread_kill().

True -- but I think there are workarounds when playing with signal
masks.

> - if you call sigalarm() from whatever thread, how could sigalarm 
> deliver the signal to that thread ? sigalarm has no knowledge of 
> threads, only of processes. so the signal goes to the process, and the 
> rule for NPTL/Pthreads is that the signal is delivered to one "random" 
> thread in the process (respecting sigmask !!! that's the point)

Oh, this is the answer :) So, sigalarm delivers the signal to a process
(according to this guy).

> - sigmask is per-thread. signal and signal handlers are per process.

true, but signal can be per thread also (with pthread_kill)

>  
> Is this true!!!
> 
> Thanks in Advance
> Divij 
> 
> > PS: Sorry for the late answers, I was away from office lately.
> > 
> > Seb.
> > 
> > Liste de diffusion nptl
> > Pour se dsinscrire : mailto:nptl_request@bullopensource.org?subject=unsubscribe
> 
> Liste de diffusion nptl
> Pour se dsinscrire : mailto:nptl_request@bullopensource.org?subject=unsubscribe
> 
-- 
Sebastien Decugis
Bull S.A.

Liste de diffusion nptl
Pour se désinscrire : mailto:nptl_request@bullopensource.org?subject=unsubscribe