Pass RFSTOPPED to fork1() in kthread_create() to avoid a race condition

where fork1() could put the process on the run queue where it could be
snatched up by another CPU before kthread_create() had set the proper
fork handler.  Instead, we put the new kthread on the runqueue after its
fork handler has been sent.

Noticed by:	jake
Looked over by:	peter
This commit is contained in:
John Baldwin 2000-12-06 03:45:15 +00:00
parent ef80a53495
commit 960d3c68ed
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=69657

View File

@ -78,7 +78,7 @@ kthread_create(void (*func)(void *), void *arg,
if (!proc0.p_stats /* || proc0.p_stats->p_start.tv_sec == 0 */)
panic("kthread_create called too soon");
error = fork1(&proc0, RFMEM | RFFDG | RFPROC | flags, &p2);
error = fork1(&proc0, RFMEM | RFFDG | RFPROC | RFSTOPPED | flags, &p2);
if (error)
return error;
@ -99,6 +99,14 @@ kthread_create(void (*func)(void *), void *arg,
/* call the processes' main()... */
cpu_set_fork_handler(p2, func, arg);
/* Delay putting it on the run queue until now. */
if (!(flags & RFSTOPPED)) {
mtx_enter(&sched_lock, MTX_SPIN);
p2->p_stat = SRUN;
setrunqueue(p2);
mtx_exit(&sched_lock, MTX_SPIN);
}
return 0;
}