thread groups bug?
If the master thread of a thread group (PID==TGID) performs an execve() then it is possible to end up with two or more thread groups with the same TGID.
Would you be willing to have an execve() on the master thread kill all the other threads? (And thus be slightly closer to POSIX compliance).
Similarly, if the master thread exits, should all the other threads be killed too?
If a subsidary thread does an execve(), then what should happen? I can see two ways of handling it: (1) Make it seem that the master thread did an execve(), and kill all the other threads (which is closer to POSIX); and (2) allow the child thread to depart the thread group and set up by itself (as happens now).
Of course, comparing the Linux "threading" system to POSIX threads doesn't hold up very well:-/
David
Quoted 3 lines · David Howells
If the master thread of a thread group (PID==TGID) performs an
execve()then it is possible to end up with two or more thread groups with the same TGID.
How about: (3) make execve allocate a new thread group id?
-ben
Quoted 7 lines · Benjamin LaHaise
Quoted 4 lines · David Howells
If the master thread of a thread group (PID==TGID) performs an
execve()then it is possible to end up with two or more thread groups with the same TGID.How about: (3) make execve allocate a new thread group id?
It seems that the TGID must also be a valid PID so that signal handling will work correctly...
This could be solved by making PIDs independent of processes, but that's really not very nice.
David
Quoted 7 lines · David Howells
Quoted 1 line
How about: (3) make execve allocate a new thread group id?
It seems that the TGID must also be a valid PID so that signal handling will work correctly...
This could be solved by making PIDs independent of processes, but that's really not very nice.
Oh, interesting. Note that we already allocate from the pid space for other things, so it's entirely doable. Another choice would be to simply disallow the thread group leader from exec'ing. Linux threads traditionally try to remain as close to process behaviour as possible, and allowing an individual thread to exec is very useful, so I'm still in favour of allocating a new tgid.
-ben
Signature · 3 lines
"A man with a bass just walked in, and he's putting it down on the floor."
Quoted 8 lines · Benjamin LaHaise
Quoted 5 lines
It seems that the TGID must also be a valid PID so that signal handling will work correctly...
This could be solved by making PIDs independent of processes, but that's really not very nice.
Oh, interesting. Note that we already allocate from the pid space for other things, so it's entirely doable.
But we still have to be able to send signals to the TGID. If there's a guaranteed PID of the same value, then that isn't a problem (except at the moment where multiple independent thread groups of the same TGID can be constructed).
This could be done by making the PID independent of the process and giving it an ops table to direct signal handling and to control /proc/<pid> dir lookup.
BTW what other things are PIDs allocated for? I can see that PIDs won't be allocated if they are in use as PIDs, TGIDs and PGIDs. As far as I can see, get_pid() is only called by do_fork().
Quoted 2 lines
Another choice would be to simply disallow the thread group leader from exec'ing.
Hmmm... Maybe... Return what error, though?
Quoted 3 lines
Linux threads traditionally try to remain as close to process behaviour as possible, and allowing an individual thread to exec is very useful, so I'm still in favour of allocating a new tgid.
Yes, I agree that letting subsidary threads to escape the group is reasonable, but the master thread is definitely trickier:-/
As mentioned above, there'd be nothing backing the TGID, so kill() would have to search a list of thread groups too...
David