- 论坛徽章:
- 0
|
其中第二段开头说:“为什么要在597行把状态设成TASK_UNINTERRUPTIBLE呢?这是因为在get_pid()中产生一个新pid的操作必须是独占的,。。。。。。。”
下面付上文中提到的代码:
int do_fork(unsigned long clone_flags, unsigned long stack_start,
struct pt_regs *regs, unsigned long stack_size)
{
int retval = -ENOMEM;
struct task_struct *p;
DECLARE_MUTEX_LOCKED(sem);
if (clone_flags & CLONE_PID) {
/* This is only allowed from the boot up thread */
if (current->pid)
return -EPERM;
}
current->vfork_sem = &sem;
p = alloc_task_struct();
if (!p)
goto fork_out;
*p = *current;
retval = -EAGAIN;
if (atomic_read(&p->user->processes) >= p->rlim[RLIMIT_NPROC].rlim_cur)
goto bad_fork_free;
atomic_inc(&p->user->__count);
atomic_inc(&p->user->processes);
/*
* Counter increases are protected by
* the kernel lock so nr_threads can't
* increase under us (but it may decrease).
*/
if (nr_threads >= max_threads)
goto bad_fork_cleanup_count;
get_exec_domain(p->exec_domain);
if (p->binfmt && p->binfmt->module)
__MOD_INC_USE_COUNT(p->binfmt->module);
p->did_exec = 0;
p->swappable = 0;
p->state = TASK_UNINTERRUPTIBLE;/*就是这里了。。。。。*/
copy_flags(clone_flags, p);
p->pid = get_pid(clone_flags);
.....................
}
我觉得p->state = TASK_UNINTERRUPTIBLE仅设置了新分配的task_struct的state域,而目前新进程尚没挂入系统的进程队列中,不可能被调度,无论如何都不会被选中执行?那此处设置TASK_UNINTERUPTIBLE的意义到底是啥啊? |
|