Re: pthreads and signals



Boltar <boltar2003@xxxxxxxxxxx> writes:
This is probably an old old question, but if you have a multithreaded
app and you haven't set up a specific signal handling thread (all
threads bar one block all possibly signals) , is there a rough guide
to know which thread will get the signal?

It should be possible to determine this by looking at the respective
library and kernel sources, insofar available. But why do you want to
know this? Which of the threads of some process would be a good choice
for running a signal handler NOW is a descision the 'thread
scheduler' (be it the general scheduler in the kernel or 'someone
else') can 'intelligently' make because it has (or should have)
information on what all those threads are currently doing (eg being
blocked waiting for something or running on CPU) and were doing in the
past available.

[...]

(I know about old linux "threads" actually being processes so I'm
not refering to that)?

Please repeat after me (three times):

Robert Love is a moron.

Ok, after having cleared the air in this respect: 'Linux threads' are
not 'actually processes', that's a statement that doesn't make any
sense, because 'a process' is defined to be a set of ressources (like
an address spaces), shared by one or more threads of execution. The
Linux kernel implements 'kernel scheduled entities' as 'tasks',
described by a struct task_struct holding pointer to various ressource
belonging to that task (eg address space or file descriptor table). A
syscall named 'clone' exists which creates a copy of an existing
struct task_struct, and, depending on a flag argument passed to it,
either allocates new 'ressource structures' for the cloned task or
makes it reference the same the original task referenced. Depending on
what is shared and what not, this mechanism can be used to implement
both 'traditional' single-threaded UNIX(*) processes and 'UNIX(*)
pthreads'.
.



Relevant Pages

  • Re: how do threads work?
    ... >> A process cannot consider to switch task unless the flow of instructions ... >> kernel for a little help, in the form of regular timer signals. ... If you now ask, how does the kernel deliver signals, then we are no longer ...
    (comp.os.linux.development.system)
  • [Announce] Non Invasive Kernel Monitor for threads/processes
    ... To create a kernel patch that shall support methods to non-intrusively monitor ... In the case when we have multiple monitor processes, signals are sent to each ... +struct kmonitor_bucket ...
    (Linux-Kernel)
  • Re: Comments on the KSE option
    ... think M:N support in the kernel is a good idea. ... When the userland thread library issues a non-blocking ... When the userland thread scheduler switches threads ... It must also poll for blocked signals. ...
    (freebsd-current)
  • Re: Function: int recv (Socket, Buffer,Length, Flags) is returning with the error number 4
    ... That's a nice speculation by someone with little clue in kernel ... what it means from a kernel coding standpoint to "interrupt a system call". ... set to EINTR after the handler was run, there was no 'kernel state' to ... kernel can deliver signals at any time to a thread which is currently ...
    (comp.unix.programmer)
  • Re: allocating kernel threads from a pool
    ... kernel level threads to do IO, so that a user-level thread's IO calls ... you don't need signals at all. ... another thread writes a pointer to a command to another end of the ...
    (comp.unix.programmer)

Loading