what is_single_threaded() does?

From: Oleg Nesterov
Date: Tue Mar 31 2009 - 17:01:39 EST


I found this helper by accident, and I am puzzled.

/**
* is_single_threaded - Determine if a thread group is single-threaded or not
* @p: A task in the thread group in question
*
* This returns true if the thread group to which a task belongs is single
* threaded, false if it is not.
*/

But this is not what the code does? The "t->mm == mm" check below means
it also returns false if ->mm is shared with another CLONE_VM process ?

Could you explain what is right, the comment or the code?

bool is_single_threaded(struct task_struct *p)
{
struct task_struct *g, *t;
struct mm_struct *mm = p->mm;

if (atomic_read(&p->signal->count) != 1)
goto no;

Is this correct? Let's suppose the main thread dies, and the thread group
has only one live thread. In that case signal->count == 2.


if (atomic_read(&p->mm->mm_users) != 1) {
read_lock(&tasklist_lock);
do_each_thread(g, t) {

Why do_each_thread() ? for_each_process() is enough, all sub-threads use
the same ->mm.

if (t->mm == mm && t != p)
goto no_unlock;

What about use_mm() ? Looks like this needs PF_KTHREAD check.

} while_each_thread(g, t);
read_unlock(&tasklist_lock);
}

return true;

Perhaps it should be current_is_single_thread(void) ...

Oleg.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/