Re: [PATCH 2.6.13.1] Patch for invisible threads

Sripathi Kodi
2005-09-13T13:12:29Z

Andrew,

Andrew Morton wrote:
> Sripathi Kodi <sripathik@in.ibm.com> wrote:
>
>>Hi,
>>
>>When the main thread of a multi-threaded program calls 'pthread_exit' before
>>other threads have exited, it results in the other threads becoming
>>'invisible' to commands like 'ps'.
>
>
> This stuff is subtle. Let me cc some subtle people.
>
>
>>Signed-off-by: Sripathi Kodi <sripathik@in.ibm.com>
>>
>>--- linux-2.6.13.1/kernel/exit.c 2005-09-12 02:46:26.000000000 -0500
>>+++ /home/sripathi/17794/patch_2.6.13.1/exit.c 2005-09-12 02:46:15.000000000
>>-0500
>>@@ -463,9 +463,11 @@ static inline void __exit_fs(struct task
>> struct fs_struct * fs = tsk->fs;
>>
>> if (fs) {
>>- task_lock(tsk);
>>- tsk->fs = NULL;
>>- task_unlock(tsk);
>>+ if (!thread_group_leader(tsk) || !atomic_read(&tsk->signal->live)) {
>>+ task_lock(tsk);
>>+ tsk->fs = NULL;
>>+ task_unlock(tsk);
>>+ }
>> __put_fs_struct(fs);
>> }
>> }
>
>
> A comment in there would be nice.
>

Below is the patch with a comment.

Thanks and regards,
Sripathi.

Signed-off-by: Sripathi Kodi <sripathik@in.ibm.com>

--- linux-2.6.13.1/kernel/exit.c 2005-09-13 15:39:48.738542872 -0500
+++ /home/sripathi/17794/patch_2.6.13.1/exit.c 2005-09-13 15:39:27.367791720
-0500
@@ -463,9 +463,13 @@ static inline void __exit_fs(struct task
struct fs_struct * fs = tsk->fs;

if (fs) {
- task_lock(tsk);
- tsk->fs = NULL;
- task_unlock(tsk);
+ /* If tsk is thread group leader and if group still has alive
+ * threads, those threads may use tsk->fs */
+ if (!thread_group_leader(tsk) || !atomic_read(&tsk->signal->live)) {
+ task_lock(tsk);
+ tsk->fs = NULL;
+ task_unlock(tsk);
+ }
__put_fs_struct(fs);
}
}